I’m stuck on an issue I’ve come across and am unsure if it’s related to my code or if it’s related to the Geolocation plugin itself.
Basically, I am able to get the user’s current location through my web browser (Google Chrome), but the issue is that the same code does not work on either the iOS Simulator and the Genymotion (Android) emulator. Meaning, the code is unable to get the user’s location, and instead I’m greeted with the following error in the Safari console:
Should I have something similar for my iOS config? If so, let me know what I need and I can check there, that way it’ll be easier to debug (since I’ve been using the iOS Simulator to debug this)
Sorry Max, I showed you the wrong piece of code (though the code I showed you is still relevant to me trying to get the cached user location that I would get from app.ts).
Please have a look at this code that I have in my app.ts file; basically I use the Geolocation in the constructor to ask the user for permission once the app starts up. The error occurs as soon as the user presses “OK” on the Geolocation’s Alert popup.
My UserData class is a bit long, but I will type the relevant code here:
Thanks for that suggestion, I tried it but same error
Here’s my package.json file in case it’s helpful. Maybe I need to upgrade something? I noticed that cordova-plugin-gelocation isn’t under the cordovaPlugins key, but even when I specified that and ran $ ionic emulate ios again, the same error occurred, so I took it out.
I think the issue is that you are accessing geolocation before the device is ready. The browser doesn’t run into the timing issue, but on a real or emulated device you are making the call to the plugin before Cordova is ready.
Move the getUserLocation call within the platform.ready block and see if that resolves your issue
Thank you so much Chris, that makes perfect sense!
I’ll keep trying to find a solution based on that knowledge (maybe when I tried it earlier and saw that same error, I was doing it incorrectly); though for anyone else that might have more suggestions or more wisdom to share, please feel free! In the mean time I’ll update you guys on whether or not these suggestions work
It says in the error that the code is 2 for POSITION_UNAVAILABLE. But I don’t know why because I have Custom Location enabled on my iOS Simulator. Hope this helps anyone with potential suggestions on how I can address the issue I’ve come across.
I haven’t tested location on an Emulator recently so I don’t know if it’s still a problem for me, but I was able to get around this by testing location-related features on an actual iOS device… (meaning to say, it will work on devices but for whatever reason it didn’t work for me in the past on the emulator)
Hi all,
I have the same problem with a very simple app with a button that shows an alert with the local coordinates, using Geolocation.getCurrentPosition().
It works with Chrome on my pc (with ionic serve), but doesn’t work with Ionic View and if I publish the app as PWA.
I’ve installed the plugin in this way: ionic plugin add cordova-plugin-geolocation
and imported it in the page in this way: import { Geolocation } from 'ionic-native';
I think that it is strange that in the file “package.json” there is no reference to the geolocation plugin.
Could be this the problem?
Has someone solved the problem?
I’ve:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.0.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.2
Xcode version: Not installed