Geolocation html5地理位置跟踪
我是HTML5地理定位的新手,是否有任何网站或示例显示如何使用HTMLGeolocationAPI跟踪其他设备的位置。此外,例如,我如何使用HTML5地理定位找到离我最近的汽车经销商,比如说距离我5或10英里? 任何示例都会非常有用Geolocation html5地理位置跟踪,geolocation,Geolocation,我是HTML5地理定位的新手,是否有任何网站或示例显示如何使用HTMLGeolocationAPI跟踪其他设备的位置。此外,例如,我如何使用HTML5地理定位找到离我最近的汽车经销商,比如说距离我5或10英里? 任何示例都会非常有用 谢谢我无法与追踪设备通话,但我一直在写一些东西,可能对你问题的第二部分有所帮助 //check browser support if(navigator.geolocation) { //do the geolocation stuff
谢谢我无法与追踪设备通话,但我一直在写一些东西,可能对你问题的第二部分有所帮助
//check browser support
if(navigator.geolocation) {
//do the geolocation stuff
navigator.geolocation.getCurrentPosition(function(position) {
//make a string out of the coordinates
var initloc_str = position.coords.latitude + ', ' + position.coords.longitude;
//pass it to a function that searches for donut shops near the coordinates
donutSearch(initloc_str);
});
} else { // if no browser support, error message or whatever
我的甜甜圈店搜索功能基于谷歌的Ajax搜索API中的本地搜索,我发现这一点很有用。该API最近被弃用,但我还没有弄清楚如何使用新的自定义搜索API进行本地搜索。我无法与跟踪设备交谈,但我一直在写一些东西,可能对您问题的第二部分有所帮助
//check browser support
if(navigator.geolocation) {
//do the geolocation stuff
navigator.geolocation.getCurrentPosition(function(position) {
//make a string out of the coordinates
var initloc_str = position.coords.latitude + ', ' + position.coords.longitude;
//pass it to a function that searches for donut shops near the coordinates
donutSearch(initloc_str);
});
} else { // if no browser support, error message or whatever
我的甜甜圈店搜索功能基于谷歌的Ajax搜索API中的本地搜索,我发现这一点很有用。该API最近被弃用,但我还没有弄清楚如何使用新的自定义搜索API进行本地搜索。您可以注册一个跟踪用户位置的函数:
var watchId = navigator.geolocation.watchPosition(function(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
});
您可以取消注册:
navigator.geolocation.clearWatch(watchId);
您可以注册跟踪用户位置的功能:
var watchId = navigator.geolocation.watchPosition(function(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
});
您可以取消注册:
navigator.geolocation.clearWatch(watchId);
这将让您对HTML5地理定位功能有一个非常棒的概述。这将让您对HTML5地理定位功能有一个非常棒的概述