8 Replies Latest reply on Jan 15, 2018 8:04 AM by williw87391704

    How do I add permissions for location (gmaps v3) for android 6+ in phonegap

    thijsw99376340

      Hello,

       

      When I test my app with chrome browser or the phonegap app. The HTML5 geolocation I'm using works just fine. (show a map view with device location)

       

      When I sign my apk with phonegap build and test the apk on a device I'm getting a Location error.

      I'm trying to add permission for geolocation, but I can't make it work.

       

      Is HTML5 geolocation the problem or is it a permission issue?

      I'm not really sure how to add permissions correctly with android 6 and above.

       

      I've read a lot of tutorials/posts about adding maps to phonegap. But they are all different and for older versions of maps/android.

       

      Greets,

       

      Thijs

        • 1. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
          simon.macdonald Adobe Employee

          Did you add cordova-plugin-geolocation to your app?

          • 2. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
            thijsw99376340 Level 1

            yes,

             

            cordova plugin add cordova-plugin-geolocation

            Plugin "cordova-plugin-geolocation" already installed on android.

            Plugin "cordova-plugin-geolocation" already installed on browser.

            • 3. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
              thijsw99376340 Level 1

              ok I've got it working, really have no idea how, but it was something with the config.xml file.

              • 4. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
                adolfh92303921

                i have done geolocation on a Android app it works fine only when GPS LOCATION enabled on mobile how do i detect GPS LOCATION and prompt user to enable and use the app

                • 5. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
                  williw87391704

                  Hello thijs, could you please post your config.xml file? I've the same problem.

                  Thank you :-)

                  • 6. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
                    nugrohor79979031

                    I have the same problem.

                    I am using cordova version 8.0.0. I've issued cordova patform add android and cordova plugin add cordova-plugin-geolocation. The config.xml is here 'gmtest/config.xml at master · goparklubanic/gmtest · GitHub '.

                    Some additional information, when i installed it into my devices run android 7.0.0 also my another that run older android version, the device prompt message that the application does not require any device feature, include gps. Then when I ran the application I got error message with error code = 2, the application does not have sufficient geolocatiion permission.

                    I try to modify android res config.xml and androidmanifest.xml to add such following code

                    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

                    and

                    <plugin name="Geolocation" value="org.apache.cordova.GeoBroker" />

                     

                    but it does not solve the problem. I build the apk via build.phonegap.com

                    • 7. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
                      jamesm45981513

                      I have the same issue as above - iOS Location Services are fine, but it won't allow location service permissions to be requested on Android. Below is my config.

                       

                      <?xml version="1.0" encoding="UTF-8"?>

                      <!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->

                      <widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="cloud.demo.nic56" version="1.0.0" android-versionCode="10000">

                         <name>Demo App</name>

                         <description>Booking Application</description>

                         <author href="https://www.demo.it" email="support@demo.it">demo.com</author>

                         <preference name="deployment-target" value="7.0" />

                         <preference name="orientation" value="portrait" />

                         <preference name="target-device" value="handset" />

                         <preference name="prerendered-icon" value="false" />

                         <preference name="detect-data-types" value="false" />

                         <preference name="exit-on-suspend" value="false" />

                         <preference name="auto-hide-splash-screen" value="true" />

                         <preference name="disable-cursor" value="false" />

                         <preference name="android-installLocation" value="auto" />

                         <preference name="ShowSplashScreenSpinner" value="false" />

                         <preference name="DisallowOverscroll" value="true" />

                        

                        <plugin name="cordova-plugin-device" />

                        <plugin name="cordova-plugin-whitelist" />

                        <plugin name="cordova-plugin-dialogs" />

                        <plugin name="cordova-plugin-geolocation" />

                        <plugin name="cordova-plugin-media" />

                        <plugin name="cordova-plugin-globalization" />

                        <plugin name="cordova-plugin-network-information" />

                        <plugin name="cordova-plugin-splashscreen" />

                        <plugin name="cordova-plugin-vibration" />

                        <plugin name="cordova-plugin-actionsheet" />

                        <plugin name="cordova-plugin-camera" />

                        <plugin name="cordova-plugin-statusbar" />

                       

                       

                         <plugin name="card.io.cordova.mobilesdk"/>

                         <plugin name="cordova-plugin-datepicker" source="npm" />

                        

                      <gap:config-file platform="ios" parent="NSPhotoLibraryUsageDescription" overwrite="true">

                         <string>We are using the photo library to allow customers to upload a profile photograph of themselves.</string>

                      </gap:config-file>

                      <gap:config-file platform="ios" parent="NSCameraUsageDescription" overwrite="true">

                         <string>We are using the Camera to allow customers to upload a profile photograph of themselves.</string>

                      </gap:config-file>

                      <gap:config-file platform="ios" parent="NSLocationWhenInUseUsageDescription" overwrite="true">

                         <string>We are using Location services to assist in the booking process of rides.</string>

                      </gap:config-file>

                       

                       

                      <icon src="res/icon.png" />

                      <splash src="res/splash.png" />

                       

                       

                      <access origin="http://*" />

                      <access origin="https://*" />

                      <allow-navigation href="*" />

                      <allow-intent href="*" />

                       

                       

                      <platform name="android">

                       

                       

                          <config-file target="AndroidManifest.xml" parent="/*">

                              <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

                              <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

                          </config-file>

                       

                       

                      <icon src="res/icon/android/icon-36-ldpi.png" qualifier="ldpi" />

                      <icon src="res/icon/android/icon-48-mdpi.png" qualifier="mdpi" />

                      <icon src="res/icon/android/icon-72-hdpi.png" qualifier="hdpi" />

                      <icon src="res/icon/android/icon-96-xhdpi.png" qualifier="xhdpi" />

                      <icon src="res/icon/android/icon-144-xxhdpi.png" qualifier="xxhdpi" />

                      <icon src="res/icon/android/icon-192-xxxhdpi.png" qualifier="xxxhdpi" />

                       

                      <splash src="res/splash/android/screen-ldpi-portrait.png" qualifier="port-ldpi" />

                      <splash src="res/splash/android/screen-mdpi-portrait.png" qualifier="port-mdpi" />

                      <splash src="res/splash/android/screen-hdpi-portrait.png" qualifier="port-hdpi" />

                      <splash src="res/splash/android/screen-xhdpi-portrait.png" qualifier="port-xhdpi" />

                      <splash src="res/splash/android/screen-xxhdpi-portrait.png" qualifier="port-xxhdpi" />

                      <splash src="res/splash/android/screen-xxxhdpi-portrait.png" qualifier="port-xxxhdpi" />

                      </platform>

                      <platform name="ios">

                              <icon src="res/icon/ios/icon-29.png" width="29" height="29" />

                              <icon src="res/icon/ios/icon-48.png" width="48" height="48" />

                              <icon src="res/icon/ios/icon-57.png" width="57" height="57" />

                              <icon src="res/icon/ios/icon-58.png" width="58" height="58" />

                              <icon src="res/icon/ios/icon-64.png" width="64" height="64" />

                              <icon src="res/icon/ios/icon-72.png" width="72" height="72" />

                              <icon src="res/icon/ios/icon-76.png" width="76" height="76" />

                              <icon src="res/icon/ios/icon-114.png" width="114" height="114" />

                              <icon src="res/icon/ios/icon-120.png" width="120" height="120" />

                              <icon src="res/icon/ios/icon-144.png" width="144" height="144" />

                              <icon src="res/icon/ios/icon-152.png" width="152" height="152" />

                              <icon src="res/icon/ios/icon-167.png" width="167" height="167" />

                              <icon src="res/icon/ios/icon-180.png" width="180" height="180" />

                              <icon src="res/icon/ios/icon-320.png" width="320" height="320" />

                              <icon src="res/icon/ios/icon-1024.png" width="1024" height="1024" />

                              <splash src="res/splash/ios/splash-screen-320-portrait.png" width="320" height="480" />

                              <splash src="res/splash/ios/splash-screen-640-iphone5-portrait.png" width="640" height="1136" />

                              <splash src="res/splash/ios/splash-screen-640-portrait.png" width="640" height="960" />

                              <splash src="res/splash/ios/splash-screen-750-portrait.png" width="750" height="1334" />

                              <splash src="res/splash/ios/splash-screen-768-portrait.png" width="768" height="1024" />

                              <splash src="res/splash/ios/splash-screen-1080-portrait.png" width="1080" height="1920" />

                              <splash src="res/splash/ios/splash-screen-1242-portrait.png" width="1242" height="2208" />

                              <splash src="res/splash/ios/splash-screen-1536-portrait.png" width="1536" height="2048" />

                      </platform>

                      </widget>

                      App ID: 2968798

                      • 8. Re: How do I add permissions for location (gmaps v3) for android 6+ in phonegap
                        williw87391704 Level 1

                        For me I've solved the problem.

                        Below there is my config.xml

                         

                        I've also used this demo-App: http://www.nik-lochmann.de/cordova-diagnostic-plugin-example-master.zip

                         

                        Hope this helps.

                        Best greetings from Germany

                         

                         

                         

                        <?xml version='1.0' encoding='utf-8'?>

                        <widget

                        id = "de.williwespe.earth"

                        version = "2.0.0"

                                xmlns="http://www.w3.org/ns/widgets"

                                xmlns:android="http://schemas.android.com/apk/res/android"

                                xmlns:cdv="http://cordova.apache.org/ns/1.0"

                                versionCode = "70"

                                android-versionCode="70">

                            <name>Earth Speed</name>

                            <description>

                                How fast does the earth move? Check it out!

                            </description>

                            <author email="willi.wespe@gmail.com" href="http://www.max-mustermann.de">

                                    WilliWespe

                            </author>

                            <content src="index.html" />

                            <access origin="*" />

                         

                         

                            <preference name="Fullscreen" value="false" /> <!-- Phonegap Build only -->

                         

                         

                            <plugin name="cordova-plugin-whitelist" version="*" />

                            <plugin name="cordova-plugin-device" version="*" />

                            <plugin name="cordova-custom-config" version="*" />

                            <plugin name="cordova-plugin-geolocation" version="2.1.0" />

                            <plugin name="cordova-plugin-camera" version="2.1.0" />

                            <plugin name="cordova-plugin-file" version="4.3.3" />

                         

                         

                            <plugin name="cordova.plugins.diagnostic" version="*" />

                            <!--<plugin spec="https://github.com/dpa99c/cordova-diagnostic-plugin.git#dev" source="git" />-->

                         

                         

                            <platform name="android">

                         

                        <icon src="www/icon.png" />

                                <plugin name="cordova-plugin-file" version="*" />

                         

                         

                                <preference name="android-build-tool" value="gradle" /> <!-- Phonegap Build only -->

                               

                                <preference name="android-minSdkVersion" value="21" />

                                <preference name="android-targetSdkVersion" value="23" />

                         

                         

                                <config-file target="AndroidManifest.xml" parent="/*">

                                    <!--<uses-permission android:name="android.permission.BLUETOOTH" />

                                    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

                         

                         

                                    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

                                    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>

                         

                         

                                    <uses-permission android:name="android.permission.RECORD_AUDIO"/>

                         

                         

                                    <uses-permission android:name="android.permission.CAMERA" />

                                    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

                                    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

                         

                         

                                    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->

                                    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

                                    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

                                    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

                         

                         

                                    <!--<uses-permission android:name="android.permission.READ_CONTACTS" />

                         

                         

                                    <uses-permission android:name="android.permission.READ_CALENDAR" />-->

                                </config-file>

                            </platform>

                         

                         

                            <platform name="ios">

                                <plugin spec="https://github.com/transistorsoft/cordova-plugin-background-fetch.git#3.0.4" source="git" />

                                <plugin name="phonegap-plugin-push" version="*">

                                    <param name="SENDER_ID" value="12345678" />

                                </plugin>

                         

                         

                                <!-- Set properties for remote notifications -->

                                <config-file platform="ios" target="*-Info.plist" parent="UIBackgroundModes">

                                    <array>

                                        <string>fetch</string>

                                        <string>remote-notification</string>

                                    </array>

                                </config-file>

                         

                         

                            </platform>

                         

                         

                            <platform name="windows">

                                <preference name="windows-target-version" value="10.0" />

                                <preference name="target-device" value="universal" />

                                <preference name="Windows.Universal-MinVersion" value="10.0.0.0" />

                            </platform>

                        </widget>