function getPosition(callback) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
latitude = position.coords.latitude;// 获取纬度
longitude = position.coords.longitude;// 获取经度
//alert(latitude + " " + longitude)
callback(latitude,longitude);//回调函数传入经度纬度
});
} else {
alert("不支持定位功能");
}
}
getPostion(function(x,y){
alert(x+" "+y);
})
iphone手机需要在https下才能获取成功
本文介绍了一个JavaScript函数,用于获取设备的地理坐标,包括纬度和经度。该函数使用navigator.geolocation API,如果设备支持,将调用getCurrentPosition方法并返回坐标。在iPhone上,此功能需要在HTTPS环境下运行。
8826

被折叠的 条评论
为什么被折叠?



