Skip to content

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。
PropertiesTypeDefault valueRequiredDescription
typestringwgs84Nowgs84 returns gps coordinates, gcj02 returns coordinates that can be used for wx.openLocation
altitudestringfalseNoPassing true will return altitude information. Since obtaining altitude requires high accuracy, it will slow down the interface return speed
successFunction-NoCallback function for successful interface call
failFunction-NoCallback function for failed interface call
completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object res
PropertiesTypeDescription
latitudenumberLatitude, range is -90~90, negative number indicates south latitude
longitudenumberLongitude, range is -180~180, negative number indicates west longitude
speednumberSpeed, unit m/s
accuracynumberPosition accuracy
altitudenumberHeight, unit m
verticalAccuracynumberVertical accuracy, unit m (cannot be obtained on Android, return 0)
horizontalAccuracynumberHorizontal 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。
PropertiesTypeDefault valueRequiredDescription
typestringwgs84Nowgs84 returns gps coordinates, gcj02 returns coordinates that can be used for wx.openLocation
successFunction-NoCallback function for successful interface call
failFunction-NoCallback function for failed interface call
completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object res
PropertiesTypeDescription
latitudenumberLatitude, range is -90~90, negative number indicates south latitude
longitudenumberLongitude, 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;
  },
});