我有这个代码来启用设备上的 GPS。
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
displayPosition,
displayError,
{ enableHighAccuracy: true, maximumAge: 0 }
);
} else {
alert('Geolocation is not supported by this browser');
}
function displayPosition(position) {
var dc_latlong = new google.maps.LatLng(position.coords.latitude.toFixed(6), position.coords.longitude.toFixed(6));
var gps_accuracy = position.coords.accuracy;
var dc_options = {
minZoom: 4,
maxZoom: 20,
center: dc_latlong,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
}
var dc_map = new google.maps.Map(document.getElementById('google-maps-distance'), dc_options);
var dc_marker = new google.maps.Marker({
position: dc_latlong,
draggable: false,
map: dc_map
});
var dc_circle = new google.maps.Circle({
center: dc_latlong,
radius: gps_accuracy,
map: dc_map,
fillColor: '#3333ff',
fillOpacity: 0.2,
strokeColor: '#3333ff',
strokeOpacity: 0.5,
strokeWeight: 1
});
google.maps.event.trigger(dc_map, 'resize');
dc_map.fitBounds(dc_circle.getBounds());
$('#gps-information').show();
$('#gps-accuracy').html(number_format(gps_accuracy) + ' meters');
}
function displayError(error) {
var errors = {
1: 'Permission denied',
2: 'Position unavailable',
3: 'Request timeout'
};
alert('Error: ' + errors[error.code]);
}
我现在想知道如何禁用设备上的 GPS,这样网站就不会一直获取访问者的位置?
提前致谢。