-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
Hello, thank you for your work.
It would be great if you could include an option in this plugin for web apps.
I know cordova is for native apps, but there could be an easy implementation with the Google API or even NOMINATIM open API:
Here is how I implemented it, it would be better to have all in one...
async saveCurrentCity(lat: number, lng: number, uid: string) {
let loadedCity: string;
if (Capacitor.getPlatform() !== "web") {
loadedCity = await this.getCityForNativeApps(lat, lng);
}
if (Capacitor.getPlatform() === "web") {
loadedCity = await this.getCityForWeb(lat, lng);
}
await this.updateUserLocation(uid, { updated_at: new Date(), city: loadedCity });
return loadedCity;
}
async getCityForNativeApps(lat: number, lng: number) {
const options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5,
};
try {
const result: NativeGeocoderResult[] = await this.nativeGeocoder.reverseGeocode(lat, lng, options);
if (result[0] && result[0].subLocality) {
return JSON.stringify(result[0].subLocality);
} else {
console.log("No subLocality found");
}
} catch (error) {
console.log("NativeGeocoder ERROR", error);
}
}
async getCityForWeb(lat: number, lng: number) {
try {
let response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}`);
let data = await response.json();
return data.address.suburb;
} catch (error) {
console.error("getCityForWeb ERROR", error);
}
}
Metadata
Metadata
Assignees
Labels
No labels