The below capability will allow a merchant to fetch the user location by calling the below method. A merchant can import the PhonePe Switch JS SDK to call the below method. The JS SDK can be imported using the npm package as mentioned here.


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


//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
  .then((location) => { 
  	console.log("Location received"+ String ) 
  .catch((err) => { 
  	console.log("Error found when fetching location = " + err) 

<html-block html=”

Response Parameters


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:

LOCATION_FETCH_FAILUREUnable to fetch user’s location
Promise resolve:
  String : which needs to be JSON.PARSE by merchant to fetch the below details. 
  'latitude': 123.123, 
  'longitude': 345.345

Promise reject:
  'error_code': 'LOCATION_FETCH_FAILURE'