title: Taro.chooseLocation(option)
sidebar_label: chooseLocation
Opens the map to select a location.
Reference
Type
(option: Option) => Promise<SuccessCallbackResult>
Parameters
Option
| Property |
Type |
Required |
Description |
| latitude |
number |
No |
Latitude. |
| longitude |
number |
No |
Longitude. |
| 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 |
| address |
string |
Detailed address |
| latitude |
string |
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 |
string |
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. |
| name |
string |
Location name |
| errMsg |
string |
Call result |
Sample Code
// config/index.js// Once you have obtained the api key, you will need to fill it into the project's constant configuration `defineConstants.LOCATION_APIKEY`:const config = { defineConstants: { LOCATION_APIKEY: JSON.stringify('XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX') }, // ...}
API Support
| API |
WeChat Mini-Program |
H5 |
React Native |
| Taro.chooseLocation |
✔️ |
✔️ |
|