Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  124] [ 2]  / answers: 1 / hits: 24346  / 12 Years ago, sun, may 20, 2012, 12:00:00

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!


More From » google-maps

 Answers
4

In this example, you are passing two distinct numerical values into a constructor and then assigning the newly created object to wickedLocation:



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


In this example, you're passing a single string value into a constructor that requires two distinct numerical coordinates:



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


The data types are both completely different.



With that said, if you want to represent a coordinate as a single object, you can do so like this:



var myHome = { lat : 44.767778 , long : -93.2775 };

var yourHome = { lat : 23,454545 , long : -92.12121 };


Then when you need to create the coords object from Google, you can pass the data in as individual arguments derived from a single object:



var wickedLocation =  new google.maps.LatLng( myHome.lat, myHome.long );

[#85465] Friday, May 18, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leslijessalyng

Total Points: 650
Total Questions: 85
Total Answers: 109

Location: Croatia
Member since Mon, Sep 6, 2021
3 Years ago
leslijessalyng questions
Fri, Feb 21, 20, 00:00, 4 Years ago
Tue, Jul 30, 19, 00:00, 5 Years ago
Fri, Jul 5, 19, 00:00, 5 Years ago
Wed, Mar 13, 19, 00:00, 5 Years ago
;