I wrote a map page that uses geolocation to detect the user's location. When the user clicks a button, this javascript is called:
if (navigator.geolocation) {
wpid = navigator.geolocation.watchPosition(function (position) {
setUserPosition(position, "Your location", pollUserPosition);
},
function() { handleNoGeolocation(true); },
{ enableHighAccuracy: false, maximumAge: 30000, timeout: 10000 }
);
}
From what I understand, watchPosition will start po开发者_开发知识库lling the user's location until it's told to stop. This is done by calling clearWatch and passing in the wpid from the watchPositon call. setUserPosition will create a marker on the map based upon the location in position. When I test this page in mobile safari sometimes I get two initial locations marked on the map. Does anyone know why I'd get two locations returned and how I can only return one? Is it because a location is returned using both the cell connection and the wifi connection on the iPhone?
Update: As a test, I turned off WiFi on the phone and tested the map page again. Unfortunately, I'm still getting two initial locations when I call watchPosition.
with watchPosition, you will get updated position information on the callback if the position data changes either by device movement or if more accurate geo information arrives.
So if you want only ONE position try using the:
navigator.geolocation.getCurrentPosition
This should only return ONE position. Have you tried that already?
精彩评论