getLocation
Supported Version
Started support in
zpa
(Zalopay App) 9.18.0 for Android, version 9.19.0 for iOS and all versions of zpi
(Zalopay in Zalo App)Description
Get the user's current location. MiniApp can only get location information depending on the user's permission choice (Always allow, Allow one-time access, Do not allow)
Parameters
Param | Data type | Required | Description |
---|---|---|---|
accuracy | string | No | Specifies the desired accuracy level for the location. Possible values are "high" , "medium" , and "low" . Defaults to "medium" . See details below. Only supported on ZPA |
isCustom | boolean | No | Choose get location with customize mode. Default is false. Read more get location flow • false: getLocation will include complex get location logic ( checkLocationPermission , requestLocationPermission )• true: available for customize get location UX Only supported on ZPA |
appId | number | No | App ID is issued when registering merchant, Zalopay team will provide this info. |
showServiceAlert | boolean | No | Whether to display the OS-level alert prompting the user to enable device location services when they are off. Defaults to true. If set to false, the API will suppress the alert and immediately return error code 160105. Only supported on Android ZPA. |
Accuracy Levels
High Accuracy
- Description: Provides the most precise location data.
- Typical Precision: Within a few meters (1-10 meters).
- Use Cases: Navigation apps, ride-sharing services, fitness tracking, augmented reality.
- Battery Consumption: High, due to continuous use of GPS and other sensors.
Medium Accuracy
- Description: Balances precision and resource consumption.
- Typical Precision: Within 10-100 meters.
- Use Cases: Location tagging in social apps, local search, weather apps.
- Battery Consumption: Moderate, utilizing a combination of GPS, Wi-Fi, and cellular data.
Low Accuracy
- Description: Provides the least precise location data.
- Typical Precision: Greater than 100 meters.
- Use Cases: General location awareness, regional content delivery, demographic analysis.
- Battery Consumption: Low, often relying on cell tower triangulation and Wi-Fi.
Return Value
Param | Data type | Description |
---|---|---|
longitude | string | Longitude value of current location |
latitude | string | Latitude value of current location |
city | string | City value of current location |
district | string | District value of current location |
ward | string | Ward value of current location |
street | string | Street value of current location |
countryCode | string | Country code value of current location |
accuracy | string | Accuracy of location data in meters |
timestamp | string | Timestamp (in milliseconds) at which the location was retrieved |
Error Code
Error Code | Description |
---|---|
010101 | The user refuses to grant location access |
010102 | The application cannot get the current location |
010103 | Location access request expired |
010104 | User deny request permission! |
010105 | The user refuses to grant permission and does not want to ask again |
010106 | User Authentication Required. Please grant User Authentication permission before requesting User Permission |
010107 | User denied |
161001 | Location permission not granted |
161002 | Location permission denied |
161003 | User deny request permission on consent form |
161004 | Please input appId |
161005 | Location service is disabled |
Sample Code and Sample Return Data
Sample Request:
window.zlpSdk.Location.getLocation({ accuracy: "high" })
.then((response) => console.log(response))
.catch((error) => console.error(error.errorCode));
Sample Response:
{
"data": {
"latitude": 37.7749,
"longitude": -122.4194,
"city": "San Francisco",
"district": "Downtown",
"ward": "Ward 2",
"street": "Market Street",
"countryCode": "US",
"accuracy": "Within a few meters (1-10 meters)",
"timestamp": 1694356800000
},
"status": "success"
}