Skip to main content

getLocation

Note
Please contact Zalopay Team to be granted permission to use this functionality.

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

ParamData typeRequiredDescription
accuracystringNoSpecifies the desired accuracy level for the location. Possible values are "high", "medium", and "low". Defaults to "medium". See details below.
Only supported on ZPA
isCustombooleanNoChoose 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
appIdnumberNoApp ID is issued when registering merchant, Zalopay team will provide this info.
showServiceAlertbooleanNoWhether 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

ParamData typeDescription
longitudestringLongitude value of current location
latitudestringLatitude value of current location
citystringCity value of current location
districtstringDistrict value of current location
wardstringWard value of current location
streetstringStreet value of current location
countryCodestringCountry code value of current location
accuracystringAccuracy of location data in meters
timestampstringTimestamp (in milliseconds) at which the location was retrieved

Error Code

Error CodeDescription
010101The user refuses to grant location access
010102The application cannot get the current location
010103Location access request expired
010104User deny request permission!
010105The user refuses to grant permission and does not want to ask again
010106User Authentication Required. Please grant User Authentication permission before requesting User Permission
010107User denied
161001Location permission not granted
161002Location permission denied
161003User deny request permission on consent form
161004Please input appId
161005Location 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"
}