搞了两天,终于把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} );
}
}
5 个评论
要回复文章请先登录或注册
4***@qq.com
d***@xdiiot.com
j***@yahoo.com
长安夜景
d***@126.com