Reputation: 95
I am building a full-stack web app in JavaScript that is intended to be used on mobile devices (Android and iPhone). Using the HTML5 Geolocation API on Android phones works great, but there appears to be an authorization issue with the iPhone. When interacting with the web app as an iPhone user, iOS automatically denies the user permission to use location services, and so unlike the Android phones, there is no pop-up that gives the user the option to allow location services. I've done a lot of tinkering with the iPhone location services settings to no avail. Is there a JavaScript snippet that enables the user to allow permission for location services? Thanks.
Upvotes: 7
Views: 7021
Reputation: 1269
Your location setting for Safari might be set to OFF
, you can change it here: Settings > Privacy > Location Services > Safari
You could also try something like this:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction);
} else {
// Make API call to the GeoIP services
}
And use some service like http://ip-api.com (but geodata based on ip is not very accurate)
Here you can find more info about getCurrentPosition():
Upvotes: 2