title: Taro.openLocation(option)

sidebar_label: openLocation

Views location using the WeChat built-in map.

Reference

Type

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

Parameters

Option

Property Type Required Description
latitude number Yes Latitude. The value ranges from -90 to +90, and the negative number means south latitude. The GCJ-02 coordinate system of the State Bureau of Surveying and Mapping is used.
longitude number Yes Longitude. The value ranges from -180 to +180, and the negative number means west longitude. The GCJ-02 coordinate system of the State Bureau of Surveying and Mapping is used.
address string No Detailed address
name string No Location name
scale number No Scale, ranging from 5 to 18
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

Sample Code

  1. Taro.getLocation({
  2. type: 'gcj02', //Returns the latitude and longitude that can be used for Taro.openLocation
  3. success: function (res) {
  4. const latitude = res.latitude
  5. const longitude = res.longitude
  6. Taro.openLocation({
  7. latitude,
  8. longitude,
  9. scale: 18
  10. })
  11. }
  12. })

API Support

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