0
我正在尝试设置我的代码,以便在Android手机或平板电脑上找到最准确的位置。由于getCurrentPosition没有给GPS足够的时间来找到一个位置,我正在使用watchPosition。这很好,但我需要允许用户停止这个watchPostion,所以我使用clearWatch函数。这clearWatch功能适用于我的Android手机2.2.2版本,但不适用于Android平板电脑3.2.1版本。我的其他问题是在我的android手机上,一旦我停止/清除表格,并尝试重新找到我的位置,我的手机就会振动并关闭浏览器。这里有什么问题?我在其他手机上也尝试过这种方法,并且遇到同样的问题。如果有人有任何建议,我将不胜感激。以下是我正在使用的代码。HTML 5地理位置手表位置
//function to locate using GPS
function ShowMyLocation(){
if (navigator.geolocation) {
ShowProgressIndicator('map');
watchID = navigator.geolocation.watchPosition(function(position){
var mapPoint = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude, new esri.SpatialReference({
wkid: 4326
})));
var graphicCollection = esri.geometry.geographicToWebMercator(new esri.geometry.Multipoint(new esri.SpatialReference({
wkid: 4326
})));
graphicCollection.addPoint(mapPoint);
geometryService.project([graphicCollection], map.spatialReference, function(newPointCollection){
HideProgressIndicator();
if (!map.getLayer(baseMapLayerCollection[0].Key).fullExtent.contains(mapPoint)) {
alert('Data not available for the specified address.');
return;
}
mapPoint = newPointCollection[0].getPoint(0);
AddServiceRequest(mapPoint);
});
}, function(error){
HideProgressIndicator();
switch (error.code) {
case error.TIMEOUT:
alert('Timeout');
break;
case error.POSITION_UNAVAILABLE:
alert('Position unavailable');
break;
case error.PERMISSION_DENIED:
alert('Permission denied');
break;
case error.UNKNOWN_ERROR:
alert('Unknown error');
break;
}
}, {
timeout: 5000,
maximumAge: 90000,
enableHighAccuracy: true
});
}
}
function clearWatch(){
// Cancel the updates when the user clicks a button.
if (watchID > 0) {
navigator.geolocation.clearWatch();
alert("Stop tracking location");
}
}
为什么在getCurrentPosition时不设置一些大的超时? – dmitry