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) from version 8.26.0 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
isForceUpdatebooleanNo (default value is false)If the value is true, the location will be continuously updated in real time. If false, the location will be taken from cache

Return Value

ParamData typeDescription
longitudestringLongitude value of current location
latitudestringLatitude value of current location

Error Code

Error CodeDescription
010101The user refuses to grant location access
010102The application cannot get the current location
010103Location access request expired

Sample Code and Sample Return Data

Sample Request:

window.zlpSdk.Device
.getLocation({ isForceUpdate: true })
.then((response) => console.log(response))
.catch((error) => console.error(error.errorCode));

Sample Response:

{ 
data: {
longitude: "106.745674"
latitude: "10.757318"
},
status: "success"
}