Taro.openLocation(option)
Views location using the WeChat built-in map.
Type
(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
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
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.openLocation | ✔️ | ✔️ |