1***@qq.com
1***@qq.com
  • 发布:2017-06-17 17:42
  • 更新:2021-07-03 03:48
  • 阅读:4967

关于html5+定位的有关经验

分类:HTML5+

搞了两天,终于把ios跟android端的定位搞明白了,直接看代码
//定位的代码要写在plusReady()里面,而且不能用mui自带的mui.plusReady(){}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}

function plusReady(){
/
android端跟ios端定位的代码是不一样的,要不然获取的地址会不准
/
if(plus.os.name == 'Android'){
var mapObj = new plus.maps.Map('allmap');

    var getGPS = mapObj.getUserLocation( function ( state, point ){  
        if( 0 == state ){  

            plus.maps.Map.reverseGeocode(point1,{},function(event){  
                var address = event.address;  // 转换后的地理位置  

                console.log("Address:"+address);  
                $('#location').text(address);  

            })  
            clientPoint.longitude = point.longitude;  
            clientPoint.latitude = point.latitude;  
        }else{  

        }  
    } );  
}  
else{  
    plus.geolocation.getCurrentPosition(function(position){  
    var point1 = new plus.maps.Point(position.coords.longitude,position.coords.latitude);  
    clientPoint.longitude = position.coords.longitude;  
    clientPoint.latitude = position.coords.latitude;  
    plus.maps.Map.reverseGeocode(point1,{},function(event){  
            var address = event.address;  // 转换后的地理位置  
            var point = event.coord;  // 转换后的坐标信息  
            var coordType = event.coordType;    // 转换后的坐标系类型  
            console.log("Address:"+address);  
            $('#location').text(address);  
            console.log(JSON.stringify(event));  
        })  
    }, function ( e ) {  

    }, {geocode:false} );  
}  

}

3 关注 分享
移动达人 8***@qq.com 2***@qq.com

要回复文章请先登录注册

4***@qq.com

4***@qq.com

怎么用
2021-07-03 03:48
d***@xdiiot.com

d***@xdiiot.com

回复 长安夜景 :
岂止不准偏的一批 查到百度的经纬度放到百度经纬度反查都查不出来 也配置百度的id了在json文件
2020-09-04 13:29
j***@yahoo.com

j***@yahoo.com

不借用其它的api?
2019-12-16 18:13
长安夜景

长安夜景

这个 安卓 定位 不准啊 楼主
2019-10-16 09:58
d***@126.com

d***@126.com

大哥,你clientPoint这个参数是在哪里定义的?
2017-07-11 15:40