# wx.getLocation(Object object)

with Promise style call: Supported

User authorization: Need scope.userLocation

Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6

Gets the current location and speed. This interface cannot be invoked when the user leaves the Mini Program. Enable high-precision positioning, interface time will increase, can be specified highAccuracyExpireTime As a timeout. The format of coordinates used in relation to the map should read gcj02。 High frequency calls cause power consumption, use persistent location interface if required wx.onLocationChangeBase library. 2.17.0 Version from wx.getLocation Increasing the call frequency limit,Related announcements

# parameter

# Object object

attribute type Default values Required Introductions Minimum version
type string wgs84 no wgs84 return gps Coordinates, gcj02 Return can be used for wx.openLocation Coordinates
altitude boolean false no to import true Altitude information is returned, slowing down the interface due to the high precision required to obtain altitude 1.6.0
isHighAccuracy boolean false no High precision positioning 2.9.0
highAccuracyExpireTime number no High-precision positioning timeout(ms), the specified time to return the highest precision, the value of more than 3000ms high precision positioning effect 2.9.0
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Callback function at the end of an interface call (both successful and unsuccessful calls are executed)

# object.success callback

# parameter
# Object res
attribute type Introductions Minimum version
latitude number Latitude, range -9090, negative indicates south latitude
longitude number Longitude, range -180180. Negative number is west longitude.
speed number Speed, unit m/s
accuracy number Accuracy of position
altitude number Height, unit m 1.2.0
verticalAccuracy number Vertical accuracy, in units m(Android Unable to get, return 0) 1.2.0
horizontalAccuracy number Horizontal precision, unit 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
 }
})

# Be careful

  • 2.17.0 risewx.getLocation` Increasing the call frequency limit,Related announcements
  • Tool positioning simulation using IP positioning, there may be some error. And tools currently only support gcj02 Coordinates.
  • When using third-party services for inverse address resolution, please confirm the third-party services default coordinate system, coordinate transformation is correct.