W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋: 打開(kāi)地圖選擇位置。需要用戶授權(quán) scope.userLocation 。使用該 API 需通過(guò)獲取用戶授權(quán)設(shè)置申請(qǐng)授權(quán)后方可對(duì)用戶發(fā)起授權(quán)申請(qǐng),可在 swan.authorize 中查看相關(guān)錯(cuò)誤碼信息。
Object object
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說(shuō)明 |
---|---|---|---|---|
success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù) | |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) | |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
參數(shù) | 參數(shù)類型 | 說(shuō)明 |
---|---|---|
name | String | 位置名稱 |
address | String | 詳細(xì)地址 |
latitude | Number | 緯度,浮點(diǎn)數(shù),范圍為 -90~90 ,負(fù)數(shù)表示南緯。使用 gcj02 國(guó)測(cè)局坐標(biāo)系,查詢指定地點(diǎn)的經(jīng)緯度。 |
longitude | Number | 經(jīng)度,浮點(diǎn)數(shù),范圍為 -180~180 ,負(fù)數(shù)表示西經(jīng)。使用 gcj02 國(guó)測(cè)局坐標(biāo)系,查詢指定地點(diǎn)的經(jīng)緯度。 |
<view class="wrap">
<view class="card-area">
<view class="list-area border-bottom">
<view class="list-item-key-4">名稱</view>
<view class="list-item-value">{{name}}</view>
</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">地址</view>
<view class="list-item-value">{{address}}</view>
</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">坐標(biāo)</view>
<view class="list-item-value">{{longitude}} {{latitude}}</view>
</view>
<button bindtap="chooseLocation" type="primary" hover-stop-propagation="true">點(diǎn)擊選擇位置</button>
</view>
</view>
Page({
data: {
longitude: '',
latitude: ''
},
chooseLocation() {
swan.authorize({
scope: 'scope.userLocation',
success: res => {
console.log('authorize', res);
},
fail: err => {
swan.openSetting({});
}
});
swan.chooseLocation({
success: res => {
console.log('chooseLocation success', res);
let longitude = 'E:' + this.formatLocation(res.longitude) + '′';
let latitude = 'N:' + this.formatLocation(res.latitude) + '′';
console.log('longitude', longitude);
console.log('latitude', latitude);
this.setData({
name: res.name,
address: res.address,
longitude: longitude,
latitude: latitude
});
},
fail: err => {
console.log('錯(cuò)誤碼:' + err.errCode);
console.log('錯(cuò)誤信息:' + err.errMsg);
}
});
},
formatLocation(data) {
return data.toFixed(2).replace('.', '°');
}
});
Q:如何查詢指定地點(diǎn)的經(jīng)緯度?
A:當(dāng)前我們提供以下方式可以查詢到您指定地點(diǎn)的經(jīng)緯度
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: