title: Taro.getLocation(option)

sidebar_label: getLocation

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

Note

  • 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.

Reference

Type

  1. (option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

Property Type Required Description
altitude string 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.
highAccuracyExpireTime number No High accuracy positioning timeout (ms), the specified time to return the highest accuracy, the value of 3000ms or more high accuracy positioning to have effect.
isHighAccuracy boolean No Turn on high accuracy positioning
type string No wgs84 returns the gps coordinates, gcj02 returns the coordinates available for Taro.openLocation
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

SuccessCallbackResult

Property Type Description
accuracy number Location accuracy
altitude number Altitude (in m)
horizontalAccuracy number Horizontal accuracy (in m)
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)
verticalAccuracy number Vertical accuracy (in m) (Not available for Android, and 0 will be returned)
errMsg string Call result

Sample Code

  1. Taro.getLocation({
  2. type: 'wgs84',
  3. success: function (res) {
  4. const latitude = res.latitude
  5. const longitude = res.longitude
  6. const speed = res.speed
  7. const accuracy = res.accuracy
  8. }
  9. })

API Support

API WeChat Mini-Program H5 React Native
Taro.getLocation ✔️ ✔️