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 | By default, "wgs84" returns gps coordinates, and "gcj02" returns coordinates that can be used for 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. |
cancel | Function | no | User cancels call |
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 returns a description of the parameters:
Parameters | Description |
---|---|
name | The 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 |