Permission for Geolocation service

iOS 13.4.1
NSB/Appstudio 8.1.0.3

I’m getting the following error on my web app:
“Origin does not have permission to use Geolocation service”
when trying to use navigator.geolocation.watchPosition

I’ve turned Location services on - is there something specific I need to do for my app?

You have to add some settings to your config.xml file.

In the old days, geolocation in cordova apps was handled via a plugin. With HTML5, geolocation is now handled by the browser. But, because it’s available doesn’t mean you can access it. In order to access the users location data you have to ask for permission and this is kinda handled automatically.

Now, the geolocation plugin no longer handles any real geolocation services but it does handle the permission so you have to include it in your project and you have to tell the user why you want access to their location.

<plugin name="cordova-plugin-geolocation" spec="4.0.2">
  <variable name="GEOLOCATION_USAGE_DESCRIPTION" value="Tell the user why you want access to their location." />
</plugin>

This is a web app - not a cordova app - I’m not sure what you mean.

Sorry, I keep forgetting that some people are doing PWA’s.

Make sure you’re only trying to use geolocation over httpS. Chrome, Firefox and Safari no longer support the API over plain ol http. There’s a deeper dive in this link.

A great tutorial on using geolocation in a PWA is here.

My PWA is hosted by Volt. Does this ensure https?

Yes, Volt is https.

Same problem here with ios 14.4.2

I am using Geolocation-app packed with Voltbuilder for ios.
When running under ios following message will be displayed:
“Geolocation error: Origin does not have permission to use Geolocation service.”

  1. Question: Under Voltbuilder, have I to use “cordova-plugin-geolocation”?
  2. I have tried following code without success:
  • In Project property
"contentSecurityPolicy":Content-Security-Policy: script-src 'self' https://www.scietrex.com https://snowmap.fast-sfc.com https://{s}.tile.opentopomap.org https://server.arcgisonline.com; 
  • In config.xml:
 <plugin name="cordova-plugin-geolocation" spec="4.0.2">
  		<variable name="GEOLOCATION_USAGE_DESCRIPTION" value="WhiteScout requires access to your location in order to get position of your ski-area." />
	</plugin>

and:

    <platform name="ios">
  	 <edit-config target="NSLocationAlwaysUsageDescription" file="Info.plist" mode="overwrite">
   		 <string>Allow the app to know your location</string>
 	 </edit-config>
 		 <edit-config target="NSLocationWhenInUseUsageDescription" file="Info.plist" mode="overwrite">
   		 <string>Allow the app to know your location</string>
  	 </edit-config>
	</platform>

and file Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationAlwaysUsageDescription</key>
<string>$(WhiteScout) requires access to your location in order to get position of your ski-area.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>$(WhiteScout) requires access to your location in order to get position of your ski-area.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>$(WhiteScout) requires access to your location in order to get position of your ski-area.</string>
</dict>
</plist>

Have anyone an idea, what to do?

In config.xml:

<plugin name="cordova-plugin-geolocation" spec="4.0.2">
  		<variable name="GEOLOCATION_USAGE_DESCRIPTION" value="WhiteScout requires access to your location in order to get position of your ski-area." />
</plugin>"

and:

<platform name="ios">
  	 <edit-config target="NSLocationAlwaysUsageDescription" file="Info.plist" mode="overwrite">
   		 <string>Allow the app to know your location</string>
 	 </edit-config>
 		 <edit-config target="NSLocationWhenInUseUsageDescription" file="Info.plist" mode="overwrite">
   		 <string>Allow the app to know your location</string>
  	 </edit-config>
</platform>

Tip : If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly.