kevinmcisaac
Posts: 37
Joined: Mon Oct 05, 2020 8:27 am

Reverse geocoding

I have a lat/long and want to turn this into an address (reverse geocoding). Cordova has a native ionic plug-in (see here)

https://masteringionic.com/blog/2017-06 ... ic-native/

I see there is a Geo Service plugin but this is for Geolocation not Geocoding.

Do you have a Geocoding plug in, if not how difficult is it to make the service from the note here
https://masteringionic.com/blog/2017-06 ... ic-native/

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Re: Reverse geocoding

Hello,

Yes, you can use this plugin in your app or just call the Google geocoding API to get the address: https://developers.google.com/maps/docu ... g/overview

kevinmcisaac
Posts: 37
Joined: Mon Oct 05, 2020 8:27 am

Re: Reverse geocoding

I'm not sure how to add the plug in. Do you have an example of adding a new Cordova native ionic plug-in

Galyna Abramovych
Site Admin
Posts: 84
Joined: Tue Mar 22, 2016 6:03 pm

Re: Reverse geocoding

Kevin,

Please check here to learn about adding custom plugins: https://docs.appery.io/docs/cordova-custom-plugins.

kevinmcisaac
Posts: 37
Joined: Mon Oct 05, 2020 8:27 am

Re: Reverse geocoding

I followed the calendar plugin tutorial (https://docs.appery.io/docs/ionic-4-cal ... n-tutorial) and got that working.

I then worked though this for the geocoder plugin and got it work, thank you!

This was quite complex (for a newbie) and I'd encourage you to add the cordova-plugin-nativegeocoder to the core.

Incase anybody else want to sue this, these are the steps I used with the cordova-plugin-nativegeocoder based on information in https://github.com/sebastianbaar/cordov ... ocoder.git. and https://ionicframework.com/docs/native/native-geocoder/ to provide the details.

  • In Resources/Cordova plugins I loaded the plugin using the github HTTP link This works successfully and shows the Plugin ID is "cordova-plugin-nativegeocoder"

  • I created a new app (Geo), which I've shared

  • in Project/App Settings/Cordova Plugins/Imported Cordova Plugins, I checked the NativeGeocoder

  • In Project > App settings > Npm modules I add a dependency @ionic-native/native-geocoder. I based this on the command "npm install @ionic-native/native-geocoder" in the npm documentation

  • In Pages > app > MODULE in IMPORTs I added import { NativeGeocoder, NativeGeocoderResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder/ngx'; based on the framework documentation

  • In NgModule Settings > Providers I added NativeGeocoder

  • In my page, ReverseGeo> CODE, I added three CUSTOM INCLUDES, { NativeGeocoder}, {NativeGeocoderResult}, {NativeGeocoderOptions } each with the path @ionic-native/native-geocoder/ngx

  • I added the variable nativeGeocoder with TYPE NativeGeocoder (from the pull down) and checked "Add DI". I also created lat and lon variable and initialised them.

  • In DESIGN I added input for lat and lon and a button with the TypeScript
    let options: NativeGeocoderOptions = {
    useLocale: true,
    maxResults: 5
    };

    this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
    .then((result: NativeGeocoderResult[]) => console.log(JSON.stringify(result[0])))
    .catch((error: any) => console.log(error));

    this.nativeGeocoder.forwardGeocode('Berlin', options)
    .then((result: NativeGeocoderResult[]) => console.log('The coordinates are latitude=' + result[0].latitude + ' and longitude=' + result[0].longitude))
    .catch((error: any) => console.log(error));

  • I then EXPORTED to Binary (.apk), and used the bar code to down load.

  • The app runs and show the page with the inputs and button but when I click on the button I get the error (viewed using the remote browser console) below indicating the plugin_not_installed.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Re: Reverse geocoding

Please use a simple REST service here as I described above. It will work the same as a plugin but without additional coding

kevinmcisaac
Posts: 37
Joined: Mon Oct 05, 2020 8:27 am

Re: Reverse geocoding

Thank for the suggetion. I've implemented both and got them working.

FYI - The benefit of the plug in on the device is it uses the device credential rather than the REST service which requires a Goolge API key.

Return to “Issues”