May 19, 2021 WeChat Mini Program Development Document
Get the current geographic location, speed. This interface cannot be called when the user leaves the program, and can continue to be called when the user clicks Show at the top of the chat.
OBJECT parameter description:
Parameters | Type | Required | Description |
---|---|---|---|
type | String | Whether |
The default is wgs84 return gps coordinates, and gcj02
wx.openLocation
|
success | Function | Is | The interface calls the successful callback function, and the return is detailed in the return parameter description. |
fail | Function | Whether | The interface calls the failed callback function |
complete | Function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Success returns a description of the parameters:
Parameters | Description | The lowest version |
---|---|---|
latitude | Latitude, floating point, range from -90 to 90, negative number indicates south latitude | |
longitude | Longness, floating point, range from -180 to 180, negative number represents the western long term | |
speed | Speed, floating point, unit m/s | |
accuracy | The accuracy of the position | |
altitude | Height, unit m | 1.2.0 |
verticalAccuracy | Vertical accuracy, unit m (Android can't get, return 0) | 1.2.0 |
horizontalAccuracy | Horizontal accuracy, unit m | 1.2.0 |
Example code:
wx.getLocation({
type: 'wgs84',
success: function(res) {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
}
})
Open the map to select a location.
User authorization is required for scope.userLocation
OBJECT parameter description:
Parameters | Type | Required | Description |
---|---|---|---|
success | Function | Is | The interface calls the successful callback function, and the return is detailed in the return parameter description. |
fail | Function | no | Interface call failed callback function |
complete | Function | no | The callback function ended in the interface call (the call is successful, failed) |
SUCCESS Return Parameter Description:
parameter | illustrate |
---|---|
name | Location name |
address | Detailed address |
latitude | Latitude, floating point, range from -90 to 90, negative number indicates south latitude |
longitude | Longness, floating point, range from -180 to 180, negative number represents the western long term |
Use WeChat's built-in map to see locations.
User authorization is required for scope.userLocation
OBJECT parameter description:
Parameters | Type | Required | Description |
---|---|---|---|
latitude | Float | Is | Latitude, ranging from -90 to 90, negative numbers indicate south latitude |
longitude | Float | Is | Longe longs, ranging from -180 to 180, with negative numbers representing the western long term |
scale | Int | Whether | Scale, range 5 to 18, default to 18 |
name | String | Whether | The location name |
address | String | Whether | A detailed description of the address |
success | Function | Whether | The interface calls a successful callback function |
fail | Function | Whether | The interface calls the failed callback function |
complete | Function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Example code:
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success: function(res) {
var latitude = res.latitude
var longitude = res.longitude
wx.openLocation({
latitude: latitude,
longitude: longitude,
scale: 28
})
}
})
bug
:
iOS
6.3.30
type parameter does not take effect and only returns coordinate information of type wgs84