I am following the guide here at http://ngcordova.com/docs/plugins/geolocation/ to get lat and lng of the user.
I copied the sample code there and when I call
getCurrentPosition() I get this error in console:
unknown provider: $cordovaGeolocation Provider
Am I missing something?
P.S. and this is the list of plugins I have installed:
com.google.playservices 23.0.0 "Google Play Services for Android" com.googlemaps.ios 1.9.2 "Google Map iOS SDK for Cordova" com.ionic.keyboard 1.0.4 "Keyboard" cordova-plugin-console 1.0.1 "Console" cordova-plugin-crosswalk-webview 1.4.0 "Crosswalk WebView Engine" cordova-plugin-device 1.0.1 "Device" cordova-plugin-splashscreen 3.0.0 "Splashscreen" cordova-plugin-whitelist 1.2.0 "Whitelist" org.apache.cordova.geolocation 0.3.12 "Geolocation"
You need to test this application on emulator or real device, not on your browser to begin with.
I did that on both android emulator and real device. And I cannot even get into the view that belongs to the controller.
When I test in browser, I also cant get into that view, but I can see the error message in the console though.
Ok, follow this checklist to be sure that you setup everything properly:
- Download ngCordova and put it as a script source in your index.html.
- Install Geolocation + Whitelist plugins:
ionic plugin add cordova-plugin-geolocation
ionic plugin add cordova-plugin-whitelist
- Reference ngCordova into your app:
var app = angular.module(‘starter’, [‘ionic’, ‘ngCordova’])
- Reference of the $cordovaGeolocation plugin into your own controller:
app.controller(‘MyGeolocation’, function($scope, $cordovaGeolocation)
- Add this meta-tag to your index.html:
meta http-equiv=“Content-Security-Policy” content=“default-src *; script-src ‘self’ ‘unsafe-inline’ ‘unsafe-eval’ *; style-src ‘self’ ‘unsafe-inline’ *”
Excellent, you are a life saver…
Now I know about the dependency it has on ngCordova, thank you!
@VolvoOlympian, Happy that it’s sorted for you, you’re welcome