plus.geolocagetCurrentPosition() 云端打包后安卓獲取不到address

問(wèn)題描述

使用plus.geolocation.getCurrentPosition()這個(gè)方法獲取定位信息,在iPhone上沒(méi)有任何問(wèn)題,在安卓上真機(jī)調(diào)試也沒(méi)有問(wèn)題,但是云端打包后再安卓上獲取不到address信息。
原創(chuàng)文章,歡迎轉(zhuǎn)載.轉(zhuǎn)載請(qǐng)注明出處: http://www.itdecent.cn/p/d9ee48dd323f
實(shí)現(xiàn)代碼如下:

//獲取位置信息
plus.geolocation.getCurrentPosition(function(p){
    mui.toast(JSON.stringify(p));
    if (!p || !p.address) {
        return;
    }
    //經(jīng)緯度
    console.log('Geolocation\nLatitude:' + p.coords.latitude + '\nLongitude:' + p.coords.longitude + '\nAltitude:' + p.coords.altitude);
   //JSON對(duì)象,地址信息
    console.log(JSON.stringify(p.address));
}, function(e){
        console.log('Geolocation error: ' + e.message);
    if (isShowToast) {
        mui.toast("定位出錯(cuò):"+e.message);
    }
});

mui.toast(JSON.stringify(p))展示的信息如下:


沒(méi)有address

解決方法

云端打包后默認(rèn)按以下優(yōu)先順序使用定位(高德定位>百度定位>系統(tǒng)定位),由于沒(méi)有集成高德和百度定位,所以使用的是系統(tǒng)定位。集成了百度定位就可以了:
依然使用上面的方法,只不過(guò)給plus.geolocation.getCurrentPosition()多加一個(gè)參數(shù){provider:'baidu'},具體代碼如下:

//使用百度地圖地位模塊獲取位置信息
plus.geolocation.getCurrentPosition(function(p){
    mui.toast(JSON.stringify(p));
    if (!p || !p.address) {
        return;
    }
    //經(jīng)緯度
    console.log('Geolocation\nLatitude:' + p.coords.latitude + '\nLongitude:' + p.coords.longitude + '\nAltitude:' + p.coords.altitude);
   //JSON對(duì)象,地址信息
    console.log(JSON.stringify(p.address));
}, function(e){
        console.log('Geolocation error: ' + e.message);
    if (isShowToast) {
        mui.toast("定位出錯(cuò):"+e.message);
    }
}, {provider:'baidu'});

然后點(diǎn)擊manifest.json文件,選SDK配置,配好對(duì)應(yīng)appkey就好了,appkey的話(huà)去百度地圖開(kāi)放平臺(tái)申請(qǐng)。
注意:申請(qǐng)Android端appkey時(shí)需要填寫(xiě)【發(fā)布版SHA1】,如果使用Hbuilder官方提供的Google賬號(hào)打包,這里就默認(rèn)填寫(xiě)官方提供的SHA1:BA:AD:09:3A:82:82:9F:B4:32:A7:B2:8C:B4:CC:F0:E9:F3:7D:AE:58

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容