Sorry, I should have been more specific, or maybe posted in a
different forum - I need it in v3, not v2. the distanceFrom() seems to
have been removed in v3.

I did, however, find a solution that might be useful for v3 - using
the Haversine formula (from
http://stackoverflow.com/questions/1502590/calculate-distance-between-two-points-in-google-maps-v3/1502821#1502821):

rad = function(x) {return x*Math.PI/180;}

distHaversine = function(p1, p2) {
  var R = 6371; // earth's mean radius in km
  var dLat  = rad(p2.lat() - p1.lat());
  var dLong = rad(p2.lng() - p1.lng());

  var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
          Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) *
Math.sin(dLong/2) * Math.sin(dLong/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c;

  return d.toFixed(3);
}

On Sep 1, 4:40 pm, "[email protected]" <[email protected]>
wrote:
> On Sep 1, 8:00 am, jrawr <[email protected]> wrote:
>
> > I was wondering if there was a way to find the distance in km, miles w/
> > e of a Google map - so, the user has the map at a certain zoom, and I
> > need to know what the distance is between the top of the map and the
> > bottom, and the left and right.
>
> The distance across the top and across the bottom will be different.
> distance across the top in meters (assuming the GMap2 object is
> "map"):
> map.getBounds().getNorthEast().distanceFrom(new
> GLatLng(map.getBounds().getNorthEast().lat(),map.getBounds().getSouthWest().lng()))
>
>   -- Larry
>
>
>
> > I need this because I want to search for videos on YouTube, and since
> > YT doesn't currently support bounding boxes (as Flickr does), I need
> > to manually input the centre location and the distances of the map
> > bounds as a radius.
>
> > Hopefully I've been clear enough, and thanks in advance for the help.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to