|
发表于 2016-7-30 16:26:50
|
显示全部楼层
中国的地图是火星地图,gps得到坐标是准确的,但是需要偏移处理。
Model.prototype.getGeolocation = function() {
function onSuccess(position) {
window.gps = function(data) {
if(data.error=="0")
{
localStorage.setItem("longitude",justep.Base64.decode(data.x));
localStorage.setItem("latitude",justep.Base64.decode(data.y));
}
};
require([ "http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=" +position.coords.longitude + "&y=" + position.coords.latitude + "&callback=gps"]);
}
function onError() {
justep.Util.hint("获取地理位置失败!", {
"delay" : 1000,
"position":'middle',
"style": "background-image:none!important;background-color:rgba(0,0,0,0.7)!important;color:white;padding-top:25px;height:80px;font-size:20px;text-align:center;"
});
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
};
以上代码是我调试过后的处理,需要百度地图的gps坐标转换,具体请看这行代码“http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=" +position.coords.longitude + "&y=" + position.coords.latitude + "&callback=gps"]”。这样处理后,安卓手机和苹果手机的gps定位后,记录坐标到本地即可。但是两个系统的误差还是有的。
不过可以控制到40米左右。
还要要注意的是,3.5打包后,需要打大包,小包的gps在小米5不起作用,华为部分手机不起作用,小米3可以正常工作。 |
|