Getting Location in Mobile UI

greg54
Tera Expert

Is there a way to get a users location when using the browser based mobile UI?

I put the "current_location" attribute on a field and was able to get the users location when using the actual Android SN Mobile app but this attribute does not affect the field when viewing in the browser mobile UI. Is there any way to get the users location when using the mobile browser?

Thanks!

1 ACCEPTED SOLUTION

greg54
Tera Expert

I figured this out for anybody who is interested in the solution. I used HTML5's built in geolocation capability with an onLoad Client Script.



if (navigator.geolocation) {


  navigator.geolocation.getCurrentPosition(UserLocation);


} else {


  alert('Geolocation is not supported by this browser');


}




// Callback function for asynchronous call to HTML5 geolocation


function UserLocation(position) {


  var latitude = position.coords.latitude;


  var longitude = position.coords.longitude;


  alert(latitude + ',' + longitude);


}


View solution in original post

6 REPLIES 6

greg54
Tera Expert

I figured this out for anybody who is interested in the solution. I used HTML5's built in geolocation capability with an onLoad Client Script.



if (navigator.geolocation) {


  navigator.geolocation.getCurrentPosition(UserLocation);


} else {


  alert('Geolocation is not supported by this browser');


}




// Callback function for asynchronous call to HTML5 geolocation


function UserLocation(position) {


  var latitude = position.coords.latitude;


  var longitude = position.coords.longitude;


  alert(latitude + ',' + longitude);


}


Thank you for posting your solution.   This is very helpful for those of us who need to determine a user's location.


kalyanrao
Kilo Explorer

Hi Greg


Can you help me on how it was done for SN Android Mobile App?



-Kalyan


Hi @kalyanrao follow this link to get user's current location using SN Android Mobile App

https://www.servicenow.com/community/developer-forum/how-to-get-users-current-location-using-now-mob...

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Adarsh Gunjan