Get Current Latitude Longitude

Faizeal Mohamed
Tera Guru

Hi,

Can we get the current position latitude and longtude through scripts?

I can see geolocation is getting the current location, but i need to get lat long through script

Any idea?

 

Thanks,

7 REPLIES 7

Brian Scott2
Tera Expert

If you'll be doing it through a client script or client controller on the service portal, you can use the HTML5 geolocation API.  Even Internet Explorer supports it.  Just a note, the users will be prompted that the page is trying to access their location.  If you do it in a client script, you'll want to view the client script in list view and set "isolate scope" to false so you'll have access to the dom.

 You can open f12 tools in your browser and paste the following script into the console to try it out.

 

function showPosition(position) {
console.log("Latitude: " + position.coords.latitude);
console.log("Longitude: " + position.coords.longitude);
}

(function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else { 
console.log("Geolocation is not supported by this browser.");
}
}())

 

I found the above information here:

 

https://www.w3schools.com/html/html5_geolocation.asp

Priyanka Vasant
Tera Guru
Hi Faizeal,

I have found one Article that might help you get solution for the same.
I have share the link please go through that.


To get latitude, longitude,timezone and UTC offset on the basis of location address


Regards,

Priyanka A.

I saw this article, in that we need to pass street name to get the lat long, without street name as parameter, is possible to get lat long?.

Try the below link

Geo Locating for Latitude and Longitude

 

Mark helpful or correct based on impact.

Regards,

Priyanka A.