Skip to main content
Version: 3.x

Taro.chooseLocation(option)

Opens the map to select a location.

Reference

Type

(option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
latitudenumberNoLatitude.
longitudenumberNoLongitude.
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
addressstringDetailed address
latitudestringLatitude. 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.
longitudestringLongitude. 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.
namestringLocation name
errMsgstringCall 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

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