# wx.getLocation(Object object)

User authorization is required for scope.userLocation before this API is called.

Gets current geographic location and speed. The API cannot be called when the user exits the Mini Program.

# Parameters

# Object object

Property Type Default Value Required Description Minimum Version
type string wgs84 No GPS coordinates are returned for WGS84, and coordinates used for wx.openLocation are returned for GCJ-02.
altitude string false No Altitude information is returned if true is passed. The API will take a longer time to respond since a higher accuracy is required to obtain the altitude. 1.6.0
success function No The callback function for a successful API call
fail function No The callback function for a failed API call
complete function No The callback function used when the API call completed (always executed whether the call succeeds or fails)

# object.success callback function

# Parameters
# Object res
Property Type Description Minimum Version
latitude number Latitude. The value ranges from -90 to +90, and the negative number means south latitude.
longitude number Longitude. The value ranges from -180 to +180, and the negative number means west longitude.
speed number Speed (in m/s)
accuracy number Location accuracy
altitude number Altitude (in m) 1.2.0
verticalAccuracy number Vertical accuracy (in m) (Not available for Android, and 0 will be returned) 1.2.0
horizontalAccuracy number Horizontal accuracy (in m) 1.2.0

# Sample Code

wx.getLocation({
 type: 'wgs84',
 success (res) {
   const latitude = res.latitude
   const longitude = res.longitude
   const speed = res.speed
   const accuracy = res.accuracy
 }
})

# Notes

  • Location simulation in the tool uses IP-based location, and there may have some error. The tool only supports GCJ-02 coordinates now.
  • When using a third-party service for reverse address resolution, please check the default coordinate system of the third-party service and perform coordinate conversion correctly.
点击咨询小助手