Geolocation: 'app/www/index.html would like to use'

When I try to get the geolocation, I get the alert window that says ‘…app/www/index.html would like to use your current location’ (see attached).

I have the app name properly defined in config.xml. How can I make sure that displays instead of index.html?

Thanks

Can you share some code how you implemented the geolocation?

I’m using this code and iOS alerts "App Name" Would Like to Use Your Current Location:

navigator.geolocation.getCurrentPosition(function(position) {
    // Success
}, function(error) {
    // Error
});

The app name is indeed from config.xml.

Could you post your config.xml?

<name>AppName</name>

and the permissions for the geolocation should be set.

Greetz, bengtler

Here’s my config.xml:

 <?xml version='1.0' encoding='utf-8'?>
 <widget id="com.madalion.fyied" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>AppName</name>
<description>
  Some descriptiond
</description>
<author email="dev@example.com” href="http://www.example.com">
  App Development Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="BackupWebStorage" value="none" />
<feature name="StatusBar">
  <param name="ios-package" value="CDVStatusBar" onload="true" />
</feature>

Here is the service code I have. The idea is to get a location update at X intervals.
In fact at app launch, I get two alert windows: one with proper app name and the second right after with ‘www/index.html’.

'use strict';

angular.module('ntf.services')
 .factory('GeoLocation', function ($interval, Constants) {
 var coords = null;
 var promise = null;



var options = {
    enableHighAccuracy: true,
    timeout: 5000,
    maximumAge: 0
  };

  function success(pos) {
    coords = pos.coords;

    if (!promise){
       promise = $interval(function(){
          navigator.geolocation.getCurrentPosition(success, error, options); 
        }, Constants.geolocationRefresh);
    }
  };

  function error(err) {
    console.warn('ERROR(' + err.code + '): ' + err.message);
    if (promise) $interval.cancel(promise);
    coords = null;
  };

  navigator.geolocation.getCurrentPosition(success, error, options); 

  return {
     coordinates: function(){
      return coords;
     } 
    };
});

Your config.xml should be good and it looks almost identical to mine. Did you run the app on the simulator or on a device?

I think you need geolocation plugin to get this working :wink:

http://cordova.apache.org/docs/en/3.3.0/cordova_geolocation_geolocation.md.html

1 Like

I am testing it on a device

Reinstalling geolocation plugin did the trick. Thanks

1 Like

@cagan327

+1 for this

image

Can you help me resolve this issue?

you probably didn’t wrap your $cordovaGeolocation function into $ionicPlatform.ready.

here is mine,it works

var located = function() {
  $ionicPlatform.ready(function() {
    $cordovaGeolocation.getCurrentPosition({
      enableHighAccuracy: false
    }).then(function(position) {
        console.log(position);
      },
      function(error) {
        $ionicLoading.show({
          template: error.message,
          duration: 1000
        });
      });
  });
};
located();

Hi @lcya86

I using code below:

  var watchGeoLocation = $cordovaGeolocation.watchPosition({
      timeout : 5*1000,
      maximumAge:10000,
      enableHighAccuracy: true // may cause errors if true
    });
  document.addEventListener("deviceready", function () {

    
    watchGeoLocation.then(
      null,
      function(err) {
        console.log("Error watch geo location:");
        console.log(err);
        
      },
      function(position) {

        var lat  = position.coords.latitude
        var long = position.coords.longitude
       
    });
  }, false);

and title not good with code

Hi @lcya86

Do you using cordova version ?

Thanks

my cordova version is 5.1.1 and my plugin is org.apache.cordova.geolocation@0.3.12
Have you ever try to put the $cordovaGeolocation.watchPosition() function into $ionicPlatform.ready()?

the gelocation call should be into the $ionicPlatform.ready()
$ionicPlatform.ready(function({
// get geolocation
}));

the gelocation call should be into the $ionicPlatform.ready()
$ionicPlatform.ready(function({
// get geolocation
}));

Moving up cordova.js in my index.html file fixed the issue.

<script src="cordova.js"></script> should be first js file.