Get User Location

Get Current Location of the User

(): Promise
Description: Call this method to get the current location of the user

Usage

//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) 
  })

<html-block html=”

Response Parameters

“>

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:

CodeDescription
LOCATION_FETCH_FAILUREUnable to fetch user’s location
Promise resolve:
{
  'latitude': 123.123, 
  'longitude': 345.345
}

Promise reject:
{
  'error_code': 'LOCATION_FETCH_FAILURE'
}