my.getLocation retrieves the current geographical location of the user, including longitude, latitude, and accuracy information.
my.getLocation({
success: (res) => {
my.hideLoading();
console.log(res);
// Update your location data
hasLocation = true;
location = formatLocation(res.longitude, res.latitude);
},
fail: () => {
my.hideLoading();
my.alert({ title: 'location failed' });
},
});
| Property | Type | Required | Description |
|---|---|---|---|
cacheTimeout | Number | No | Longitude and latitude location cache expiry time in seconds. Default is 30s. Use of cache can speed up location process. Re-location is done upon cache expiry. |
type | Number | No | 0: default, get the longitude and latitude. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
The incoming parameter is of the Object type with the following attributes:
| Property | Type | Description |
|---|---|---|
longitude | String | Longitude. |
latitude | String | Latitude. |
accuracy | String | Accuracy, in m. |
| Error | Description | Solution |
|---|---|---|
11 | Make sure the location related right has been enabled. | Prompt the user to enable location permission. |
12 | Network abnormity, try again later. | Prompt the user to check the current network. |
13 | Location failure, try again later. | - |
14 | Service location timeout. | Prompt the user to try again. |
cacheTimeout parameter can improve performance by caching location data