Skip to main content
Version: Next

Taro.getLocation(option)

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

(option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
altitudestringNoAltitude 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.
highAccuracyExpireTimenumberNoHigh accuracy positioning timeout (ms), the specified time to return the highest accuracy, the value of 3000ms or more high accuracy positioning to have effect.
isHighAccuracybooleanNoTurn on high accuracy positioning
typestringNowgs84 returns the gps coordinates, gcj02 returns the coordinates available for Taro.openLocation
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

SuccessCallbackResult

PropertyTypeDescription
accuracynumberLocation accuracy
altitudenumberAltitude (in m)
horizontalAccuracynumberHorizontal accuracy (in m)
latitudenumberLatitude. The value ranges from -90 to +90, and the negative number means south latitude.
longitudenumberLongitude. The value ranges from -180 to +180, and the negative number means west longitude.
speednumberSpeed (in m/s)
verticalAccuracynumberVertical accuracy (in m) (Not available for Android, and 0 will be returned)
errMsgstringCall result

Sample Code

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

API Support

APIWeChat Mini-ProgramH5React Native
Taro.getLocation✔️✔️