Skip to main content
Version: Next

Taro.openLocation(option)

Views location using the WeChat built-in map.

Reference

Type

(option: Option) => Promise<CallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
latitudenumberYesLatitude. 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.
longitudenumberYesLongitude. 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.
addressstringNoDetailed address
namestringNoLocation name
scalenumberNoScale, ranging from 5 to 18
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

Sample Code

Taro.getLocation({
type: 'gcj02', //Returns the latitude and longitude that can be used for Taro.openLocation
success: function (res) {
const latitude = res.latitude
const longitude = res.longitude
Taro.openLocation({
latitude,
longitude,
scale: 18
})
}
})

API Support

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