Api 若访问者的手机或平板电脑中安装了GPS,那个么就可以在网站上获得访问者的准确位置
如果访客的手机或平板电脑中有GPS,我需要在我的网站中获得访客的准确位置。。。我需要用他们的GPS获得游客的准确纬度和经度 我已经搜索了更多的手机应用程序,但所有结果显示,但我需要在基于浏览器的网站上实现 可能吗?。。有API吗?您可以使用。这不需要移动应用程序,所有主要的移动浏览器都支持该API。您可以使用它执行以下操作:Api 若访问者的手机或平板电脑中安装了GPS,那个么就可以在网站上获得访问者的准确位置,api,geolocation,location,Api,Geolocation,Location,如果访客的手机或平板电脑中有GPS,我需要在我的网站中获得访客的准确位置。。。我需要用他们的GPS获得游客的准确纬度和经度 我已经搜索了更多的手机应用程序,但所有结果显示,但我需要在基于浏览器的网站上实现 可能吗?。。有API吗?您可以使用。这不需要移动应用程序,所有主要的移动浏览器都支持该API。您可以使用它执行以下操作: MIN_ACCEPTABLE_ACCURACY = 20; // Minimum accuracy in metres that is acceptable as an "
MIN_ACCEPTABLE_ACCURACY = 20; // Minimum accuracy in metres that is acceptable as an "accurate" position
if(!navigator.geolocation){
console.warn("Geolocation not supported by the browser");
return;
}
navigator.geolocation.watchPosition(function(position){
if(position.accuracy > MIN_ACCEPTABLE_ACCURACY){
console.warn("Position is too inaccurate; accuracy="+position.accuracy");
return;
}else{
// Do something with the position
// This is the current position of your user
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
}
}, function(error){
switch(error.code) {
case error.PERMISSION_DENIED:
console.error("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
console.error("Location information is unavailable.");
break;
case error.TIMEOUT:
console.error("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
console.error("An unknown error occurred.");
break;
}
},{
timeout: 30000, // Report error if no position update within 30 seconds
maximumAge: 30000, // Use a cached position up to 30 seconds old
enableHighAccuracy: true // Enabling high accuracy tells it to use GPS if it's available
});
很好用!谢谢-这应该以W3学校为例。