On this page
Location
getLocation
TIP
The API usage is as follows: wx.getLocation(Object object)
TIP
- If this interface is used, it needs to be declared in app.json, otherwise it will not be used normally.
- User authorization scope.userLocation is required before calling.
- Functional description: Get the current geographic location and speed. When the user leaves the applet, this interface cannot be called.
- Parameters and descriptions: Object object。
| Properties | Type | Default value | Required | Description |
|---|---|---|---|---|
| type | string | wgs84 | No | wgs84 returns gps coordinates, gcj02 returns coordinates that can be used for wx.openLocation |
| altitude | string | false | No | Passing true will return altitude information. Since obtaining altitude requires high accuracy, it will slow down the interface return speed |
| success | Function | - | No | Callback function for successful interface call |
| fail | Function | - | No | Callback function for failed interface call |
| complete | Function | - | No | Callback function for interface call completion (executed regardless of success or failure) |
- object.success callback function parameters: Object res
| Properties | Type | Description |
|---|---|---|
| latitude | number | Latitude, range is -90~90, negative number indicates south latitude |
| longitude | number | Longitude, range is -180~180, negative number indicates west longitude |
| speed | number | Speed, unit m/s |
| accuracy | number | Position accuracy |
| altitude | number | Height, unit m |
| verticalAccuracy | number | Vertical accuracy, unit m (cannot be obtained on Android, return 0) |
| horizontalAccuracy | number | Horizontal accuracy, unit m |
- Sample code:
js
wx.getLocation({
type: "gcj02",
success(res) {
const latitude = res.latitude;
const longitude = res.longitude;
const speed = res.speed;
const accuracy = res.accuracy;
},
});TIP
- Position simulation in the tool uses IP positioning, which may have a certain error. And the tool currently only supports gcj02 coordinates.
- When using a third-party service for reverse address resolution, please confirm the default coordinate system of the third-party service and perform coordinate conversion correctly.
getFuzzyLocation
TIP
The API usage is as follows: wx.getFuzzyLocation(Object object)
TIP
This API is supported by mini programs, but not by mini games.
- Functional description: Get the current fuzzy geographic location.
- Parameters and descriptions: Object object。
| Properties | Type | Default value | Required | Description |
|---|---|---|---|---|
| type | string | wgs84 | No | wgs84 returns gps coordinates, gcj02 returns coordinates that can be used for wx.openLocation |
| success | Function | - | No | Callback function for successful interface call |
| fail | Function | - | No | Callback function for failed interface call |
| complete | Function | - | No | Callback function for interface call completion (executed regardless of success or failure) |
- object.success callback function parameters: Object res
| Properties | Type | Description |
|---|---|---|
| latitude | number | Latitude, range is -90~90, negative number indicates south latitude |
| longitude | number | Longitude, range is -180~180, negative number indicates west longitude |
- Sample code:
js
wx.getFuzzyLocation({
type: "wgs84",
success(res) {
const latitude = res.latitude;
const longitude = res.longitude;
},
});