Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a string as GPS coordinates

I am using javascript and I have GPS coordinates in the form of a string and I am trying to put those into the google.maps.LatLng(59.327383, 18.06747) format but am having trouble deciding how to do it. I have a variable:

GPSlocation = "(37.700421688980136, -81.84535319999998)"

and I need it to go into that google.maps.LatLng(num, num) format. How can I put this string in there?

Thanks!

like image 982
clifgray Avatar asked Dec 08 '22 21:12

clifgray


1 Answers

You can use standard string operations to extract the values:

var GPSlocation = "(37.700421688980136, -81.84535319999998)";
var LatLng = GPSlocation.replace("(", "").replace(")", "").split(", ")
var Lat = parseFloat(LatLng[0]);
var Lng = parseFloat(LatLng[1]);

google.maps.LatLng(Lat, Lng)
like image 69
john.stewart Avatar answered Dec 28 '22 08:12

john.stewart