0

I'm using google maps, and retrieving a custom field with PHP and inserting those coordinates into googlemaps using their API.

I'm stuck on the variable not working.

I should start again: Can I split the var co into Lat, Lng Removing the " and the splitting after the comma?

  var co = "-37.817852969252414,144.9671745300293";
  var map;
  var chicago = new google.maps.LatLng(Lat, Lng);
uriah
  • 2,485
  • 5
  • 28
  • 40
  • you declared the variable as `co`, not `$co` – Kevin B Jul 24 '13 at 18:06
  • Your syntax is wrong. google.maps.LatLng expects two parameters, you're giving it one. https://developers.google.com/maps/documentation/javascript/reference#LatLng – Kevin B Jul 24 '13 at 18:11
  • I think you are right geocodezip, but I can't quite find the answer. – uriah Jul 24 '13 at 18:44
  • This doesn't work? `var coords = co.split(","); chicago = new google.maps.LatLng(parseFloat(coords[0]),parseFloat(coords[1]));` (slightly modified from the linked question) – geocodezip Jul 24 '13 at 18:47

1 Answers1

1
var co = "-37.817852969252414,144.9671745300293";
var chicago = new google.maps.LatLng(co);

Should be

var lat = -37.817852969252414;
var lng = 144.9671745300293;
var chicago = new google.maps.LatLng(lat, lng);

And depending on the format of $values['coordinates'], these two values could be populated by splitting the coordinates by the comma, or if its an array setting these variables like this:

var lat = <? echo $values['coordinates']['lat'] ?>;
var lng = <? echo $values['coordinates']['lng'] ?>;
var chicago = new google.maps.LatLng(lat, lng);
Pieter Ouwerkerk
  • 43
  • 1
  • 1
  • 5
  • Sorry @pieter I'm not use to pulling PHP into jquery. It doesn't work, do I still need the ; – uriah Jul 24 '13 at 18:32