HBuilder webApp开发(十六)定位geolocation

时间:2021-09-03 13:39:43

HBuilder的geolocation定位模块其实接口很少,通常我们使用定位模块即可。
HBuilder webApp开发(十六)定位geolocation

var posi = null;
mui.plusReady(function() {
posi = plus.geolocation.getCurrentPosition( function ( p ) {
console.log( "Geolocation\nLatitude:" + p.coords.latitude + "\nLongitude:" + p.coords.longitude + "\nAltitude:" + p.coords.altitude );
console.log("street = " + p.address.street);
console.log("poiName = " + p.address.poiName);
console.log("coordsType = " + p.coordsType);
console.log("timestamp = " + p.timestamp);
console.log("addresses = " + p.addresses);
}, function ( e ) {
console.log( "Geolocation error: " + e.message );
},{enableHighAccuracy: true});
});
mui.back = function(){
var btn = ["确定","取消"];
mui.confirm('确认关闭当前窗口?','Hello MUI',btn,function(e){
if(e.index==0){
// 关闭位置监听 并返回
plus.geolocation.clearWatch( posi );
mui.currentWebview.close();
}
});
}