地理位置HTML5 getCurrentLocation回调
问题描述:
如何添加回调函数getCurrentLocation方法将坐标或位置作为参数传递给全局变量?该对象允许将坐标传递给getCurrentLocation之外的全局变量。地理位置HTML5 getCurrentLocation回调
//Global scope
var Location= {coords:null;
}
function getLocation(position)
{
position.coords.latitude;
Location.coords=coords.clone();
}
somewhere
navigator.geolocation.getCurrentLocation(getLocation, error)
Location.coords is NULL !
谢谢。
答
你可以阅读所有关于如何使用geoloction API在http://diveintohtml5.ep.io/geolocation.html这是一个梦幻般的网站。默认情况下,getCurrentLocation将回调作为参数。回调接收一个位置对象。
答
navigator.geolocation.getCurrentLocation(function(pos){
console.log("I'm located at ",pos.coords.latitude,' and ',pos.coords.longitude);
});
建议使用保罗爱尔兰的垫片为旧浏览器也回退:https://gist.github.com/366184
答
在你的代码,该行:
Location.coords=coords.clone();
使用可变coords
未声明。该函数的参数与您调用的坐标position
。这是一个错字吗?
答
Shoudn't是:
getCurrentPosition