Question

I am using the Google Maps API v3 and I'd like to get the distance between the map center and and right border of the bounding box.

My current code looks like this:

var EX1 = map.getCenter();
var EX2 = "(" + map.getCenter().lat() + ", " + map.getBounds().getNorthEast().lng() + ")";
var Radius = google.maps.geometry.spherical.computeDistanceBetween(EX1, EX2) / 1000;
alert(EX1);
alert(EX2);
alert(Radius);

EX1 and EX2 seem to have the same format, the coordinates of EX2 look correct, but the Radius alert always shows NaN (it works fine with var EX2 = map.getBounds().getNorthEast();).

Is there a way to get the distance between the center and the right border?

Thanks,

Timon

Was it helpful?

Solution

EX2 is a string. EX1 is a google.maps.LatLng object which has a method to convert it to a string. They are not "the same format". This should work (not tested):

var EX1 = map.getCenter();
var EX2 = new google.maps.LatLng(map.getCenter().lat(),map.getBounds().getNorthEast().lng());
var Radius = google.maps.geometry.spherical.computeDistanceBetween(EX1, EX2) / 1000;
alert(EX1);
alert(EX2);
alert(Radius);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top