Get Current Location of the User
Copied !
(): Promise
Description: Call this method to get the current location of the user
Usage
Example//Get the location permission from PhonePe first //See the Ask for Permissions section above to see the structure of res object let result = await sdk.seekPermission([PhonePe.Constants.Permission.LOCATION]) //If the permission has been given for location //Then get the current location //Else getCurrentLocation() would reject sdk.getCurrentLocation() .then((location) => { console.log("Location received with latitude = " + location.latitude + ' longitude = ' + location.longitude) }) .catch((err) => { console.log("Error found when fetching location = " + err) })
Promise<any>
A promise of getting the current location. Promise rejection will contain the error message if we were unable to fetch the location.
The promise rejection reason can be as follows:
Code | Description |
---|---|
LOCATION_FETCH_FAILURE | Unable to fetch user’s location |
ResponsePromise resolve: { 'latitude': 123.123, 'longitude': 345.345 } Promise reject: { 'error_code': 'LOCATION_FETCH_FAILURE' }