I am developing a website that relies on pulling the geolocation data of a mobile user. I am doing it the typical way via:
function initialize() {
if(window.google && google.gears) {
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(useLocation, errorOnLocate);
}
else if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(useLocation, errorOnLocate);
}
else {
alert("no geo found");
}
}
function errorOnLocate(message)
{
alert(message);
zoomTo(-34.397, 150.644);
}
This always fails with [object PositionError] in to the errorOnLocate function, even if I switch the geolocation method order.
This is on an HTC Hero with android 2.1 using whatever browser is built in. My gps is on and I have instructed the browser to allow websites to view my location. The "location" feature on the google map native application that comes on the phone picks up my location just fine
Further more if I visit my site using FireFox 3.5 on my personal computer it will find my location correctly.(I believe it uses a combination of ip and ap data points). Either way, it uses the same javascript.
EDIT: This is html/js in a browser, not a native app. Also the exact error message is 'The last location provider was disabled'
Is this being accessed from a
WebView
or from the Android Browser app? If from aWebView
, you may need to enable geolocation via a Java call. See the WebView reference for that.Otherwise, I'm not sure precisely what's wrong with your JS, but here's HTML+JS that I know works with the Android browser:
This wasn't working on my Android 2.4, the problem was solved by enabling Wireless Networks Location besides GPS (wasn't working with just GPS)
Settings -> Location & Privacy -> Enable Wireless Networks.
I have tested html5 geolocation functionality with the following two phones:
Both were running the Android 2.1 update1 OS and both failed to do geolocation using the built in Google browser and demo sites like:
However, I have developed my own app (using a combination of the code already presented above) that successfully runs on:
and the code I am using is:
Javascript lib:
function watchLocation(successCallback, errorCallback) { successCallback = successCallback || function(){}; errorCallback = errorCallback || function(){};
}
actual code in my html file:
Sorry this source code just does not want to format properly, message me and i'll send you the code directly if you wish so.
I was having this problem and I think it was because the power on the device was low. Charged it up and the problem went away.