Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing location coordinates to google maps as variable

Anyone know why this will work:

var wickedLocation =  new google.maps.LatLng(44.767778, -93.2775);

But this won't:

var wickedCoords = "44.767778, -93.2775";
var wickedLocation =  new google.maps.LatLng(wickedCoords);

I tried passing the latitude and longitude as separate variables and that didn't do the trick either. How can I pass the coordinates successfully as a variable? Thanks!

like image 393
coryetzkorn Avatar asked May 20 '12 20:05

coryetzkorn


1 Answers

If you are getting the coordinates as a string, in the format you showed in your example, you could do this:

var b=wickedCoords.split(",");
var wickedLocation=new google.maps.LatLng(parseFloat(b[0]), parseFloat(b[1]));
like image 160
dda Avatar answered Nov 15 '22 19:11

dda