搞了两天,终于把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} );

}

}

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐