所以我做了一些环顾四周,找不到任何真正回答我想要做的事情的东西,因此我发布了!
我的总体目标本质上是让页面读取用户位置,然后根据他们所在的位置运行代码。具体来说,我有一个 facebook 签入脚本,允许用户在特定位置签入。
问题是有问题的位置有点大,所以手动输入位置的坐标是行不通的。我现在坚持的是是否有可能告诉 JS 采用硬编码的位置的经度和纬度,但在坐标周围给出一个半径(比如说 200 米),所以当用户输入坐标的 200m 半径时代码激活。
有没有人有任何想法?
到目前为止,这是我的代码。
jQuery(window).ready(function(){
initiate_geolocation();
});
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}
function handle_errors(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query(position){
var lat = position.coords.latitude;
var long = position.coords.longitude;
//these are for testing purposes
alert('Your latitude is '+lat+' and longitude is '+long);
if (lat == 0 && long == 0) {alert('It works!');};
}