新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)小程序教程:微信小程序API查看位置
wx.getLocation(OBJECT)
獲取當(dāng)前的地理位置、速度。當(dāng)用戶離開(kāi)小程序后,此接口無(wú)法調(diào)用;當(dāng)用戶點(diǎn)擊“顯示在聊天頂部”時(shí),此接口可繼續(xù)調(diào)用。

OBJECT參數(shù)說(shuō)明:
| 參數(shù) | 類型 | 必填 | 說(shuō)明 |
|---|---|---|---|
| type | String | 否 | 默認(rèn)為 wgs84 返回 gps 坐標(biāo),gcj02 返回可用于wx.openLocation的坐標(biāo) |
| success | Function | 是 | 接口調(diào)用成功的回調(diào)函數(shù),返回內(nèi)容詳見(jiàn)返回參數(shù)說(shuō)明。 |
| fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) |
| complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
success返回參數(shù)說(shuō)明:
| 參數(shù) | 說(shuō)明 | 最低版本 |
|---|---|---|
| latitude | 緯度,浮點(diǎn)數(shù),范圍為-90~90,負(fù)數(shù)表示南緯 | |
| longitude | 經(jīng)度,浮點(diǎn)數(shù),范圍為-180~180,負(fù)數(shù)表示西經(jīng) | |
| speed | 速度,浮點(diǎn)數(shù),單位m/s | |
| accuracy | 位置的精確度 | |
| altitude | 高度,單位 m | 1.2.0 |
| verticalAccuracy | 垂直精度,單位 m(Android 無(wú)法獲取,返回 0) | 1.2.0 |
| horizontalAccuracy | 水平精度,單位 m | 1.2.0 |
示例代碼:
wx.getLocation({
type: 'wgs84',
success: function(res) {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
}
})
wx.chooseLocation(OBJECT)
打開(kāi)地圖選擇位置。
需要用戶授權(quán) scope.userLocation
OBJECT參數(shù)說(shuō)明:
| 參數(shù) | 類型 | 必填 | 說(shuō)明 |
|---|---|---|---|
| success | Function | 是 | 接口調(diào)用成功的回調(diào)函數(shù),返回內(nèi)容詳見(jiàn)返回參數(shù)說(shuō)明。 |
| fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) |
| complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
success返回參數(shù)說(shuō)明:
| 參數(shù) | 說(shuō)明 |
|---|---|
| name | 位置名稱 |
| address | 詳細(xì)地址 |
| latitude | 緯度,浮點(diǎn)數(shù),范圍為-90~90,負(fù)數(shù)表示南緯 |
| longitude | 經(jīng)度,浮點(diǎn)數(shù),范圍為-180~180,負(fù)數(shù)表示西經(jīng) |
wx.openLocation(OBJECT)
?使用微信內(nèi)置地圖查看位置。
需要用戶授權(quán) scope.userLocation
OBJECT參數(shù)說(shuō)明:
| 參數(shù) | 類型 | 必填 | 說(shuō)明 |
|---|---|---|---|
| latitude | Float | 是 | 緯度,范圍為-90~90,負(fù)數(shù)表示南緯 |
| longitude | Float | 是 | 經(jīng)度,范圍為-180~180,負(fù)數(shù)表示西經(jīng) |
| scale | INT | 否 | 縮放比例,范圍5~18,默認(rèn)為18 |
| name | String | 否 | 位置名 |
| address | String | 否 | 地址的詳細(xì)說(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í)行) |
示例代碼:
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的經(jīng)緯度
success: function(res) {
var latitude = res.latitude
var longitude = res.longitude
wx.openLocation({
latitude: latitude,
longitude: longitude,
scale: 28
})
}
})
Bug & Tip
bug:iOS6.3.30type 參數(shù)不生效,只會(huì)返回 wgs84 類型的坐標(biāo)信息
標(biāo)題名稱:創(chuàng)新互聯(lián)小程序教程:微信小程序API查看位置
網(wǎng)頁(yè)地址:http://fisionsoft.com.cn/article/djdossc.html


咨詢
建站咨詢
