Reputation: 1871
i am trying to get user current position in mobile web application
my app work in all android telephone device except samsung galaksy s2 telephone device ..
it give errror POSITION UNAVAILABLE error
this is demo link.you can view source
this is code
navigator.geolocation.getCurrentPosition(handle_geolocation_query1, handle_errors) ;
function handle_errors(error) {
switch (error.code) {
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query1(position) {
$('#map_canvas').gmap('addMarker', {
'id':'m_1',
'position': new google.maps.LatLng(position.coords.latitude,position.coords.longitude),
'bounds': true,
'icon': 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/images/gpsloc.png'
}).click(function () {
$('#map_canvas').gmap('openInfoWindow',{ 'content': '<font color="#2a2a2a" size="4">Location </font><br/><font color="#4a4a4a">Your current location</font>' }, this);
});
var map = $('#map_canvas').gmap('get', 'map');
map.setZoom(14);
map.setCenter(new google.maps.LatLng(41.01802007732287, 28.971880674362183));
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
}
edited: i used phonegap to produce android apk file when i work this apk file application it give error POSITION UNAVAILABLE error but when i call this page from web it works it does not give error ... this is web link and you can download apk from here
Upvotes: 1
Views: 12049
Reputation: 4344
I had the same error with Messenger webview, the location for Messenger was denied in phone settings so the error was resolved after allowing the location sharing for the Messenger app.
Upvotes: 0
Reputation: 1489
On my device, I had my settings for Location mode set to "Device only". In this case, I wasn't able to get a good connection of location and hence get Position Unavailable. I change my Settings > Location > Mode and change it to High Accuracy. It took me a lot of days to get this problem to work unknowingly that the problem is in the device itself. I did my best capability to fix the codes, and even traced back to the plugin's code. Please respect my post. Some people might have this problem as well. Thank you.
Upvotes: 0
Reputation: 56501
Your code is working fine in browser but not in mobile.
On checking your source code it seems you're specifying the sensor parameter as false.
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
You missed this while checking the documentation.
Specifying the Sensor Parameter
Use of the Google Maps API requires that you indicate whether your application is using a sensor (such as a GPS locator) to determine the user's location. This is especially important for mobile devices. Applications must pass a required sensor parameter to the tag when including the Maps API javascript code, indicating whether or not your application is using a sensor device.
Applications that determine the user's location via a sensor must pass sensor=true when loading the Maps API JavaScript.
Hope you understand.
Upvotes: 2