I installed the geocoder plugin in my Ionic 3 App, added it to appmodule.ts, and because it is not supported by DevApp, I build it on iOS platform and tested on a device. I am getting an error and the coordinates are not returned.
Here is my code in home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { NativeGeocoder, NativeGeocoderForwardResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
lat: string;
long: string;
error: boolean;
constructor(public navCtrl: NavController, private nativeGeocoder: NativeGeocoder) {
}
ionViewDidLoad() {
let options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.forwardGeocode('Berlin', options)
.then((coordinates: NativeGeocoderForwardResult[]) =>
{ console.log('The coordinates are latitude=' + coordinates[0].latitude + ' and longitude=' + coordinates[0].longitude);
this.lat = coordinates[0].latitude;
this.long = coordinates[0].longitude;
this.error = false;
})
.catch((error: any) => {console.log(error)
this.error = true;});
}
}
Here is my code in home.html
<ion-content padding>
<p>LAT: {{lat}}</p>
<p>LONG: {{long}}</p>
<p>ERROR: {{error}}</p>
</ion-content>
The output shows ERROR: true meaning that the plugin returned an error and of course latitude and longitude does not show.
Here are the messages I got while installing the plugin:
Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to: "$(PROJECT_DIR)/$(PROJECT_NAME)/Bridging-Header.h" for build configuration Debug
Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to: "$(PROJECT_DIR)/$(PROJECT_NAME)/Bridging-Header.h" for build configuration Release
Importing NativeGeocoder-Bridging-Header.h into /Users/M/HAPPA/platforms/ios/Happa/Bridging-Header.h
Update IOS build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to: YES for build configuration Debug
Update SWIFT version to 3.0 Debug
Update IOS build setting SWIFT_OPTIMIZATION_LEVEL to: -Onone for build configuration Debug
Update IOS build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to: YES for build configuration Release
Update SWIFT version to 3.0 Release
Here is my package.json
{
"name": "AngularApp",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/core": "~4.10.0",
"@ionic-native/native-geocoder": "^4.14.0",
"@ionic-native/splash-screen": "~4.10.0",
"@ionic-native/status-bar": "~4.10.0",
"@ionic/storage": "2.1.3",
"angularfire2": "^5.0.0-rc.6",
"cordova-ios": "~4.5.5",
"cordova-plugin-add-swift-support": "^1.7.1",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-ionic-keyboard": "^2.1.2",
"cordova-plugin-ionic-webview": "^2.1.4",
"cordova-plugin-nativegeocoder": "^3.1.2",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"firebase": "^4.12.1",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26",
"cordova-android": "~7.0.0"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.11",
"typescript": "~2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-nativegeocoder": {
"LOCATION_WHEN_IN_USE_DESCRIPTION": "Use geocoder service"
}
},
"platforms": [
"ios",
"android"
]
}
}
How can I debug this? I cannot see the error message in the console because I am testing on a device and do not know even what the problem could be.
I really would love to use the plugin instead of a third-party service.
Thanks.