As importantly, Shah's method assumes the world is "round."  Which it
is not.

And changing the prototype of any google function is really asking for
trouble (because of the way the way Google functions iterate over
their own properties.)

- Jeff

On Aug 19, 7:23 am, "[email protected]" <[email protected]>
wrote:
> On Aug 19, 7:02 am, shah <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > google.maps.LatLng.prototype.distanceFrom = function (newLatLng) {
>
> >         //var R = 6371; // km (change this constant to get miles)
>
> >         var R = 6378100; // meters
>
> >         var lat1 = this.lat();
>
> >         var lon1 = this.lng();
>
> >         var lat2 = newLatLng.lat();
>
> >         var lon2 = newLatLng.lng();
>
> >         var dLat = (lat2 - lat1) * Math.PI / 180;
>
> >         var dLon = (lon2 - lon1) * Math.PI / 180;
>
> >         var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
>
> >         Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI /
> > 180) *
>
> >         Math.sin(dLon / 2) * Math.sin(dLon / 2);
>
> >         var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
>
> >         var d = R * c;
>
> >         return d;
>
> >     }
>
> > usage :
>
> >  var point = new google.maps.LatLng(lat,lng)
> > var distance = point.distanceFrom(anotherPoint);
>
> Why do it the hard way. That is built into the geometry library.
>
> http://code.google.com/apis/maps/documentation/javascript/geometry.html
>
>   -- Larry
>
>
>
>
>
>
>
>
>
> > On Aug 19, 8:50 am, Natxo Vergara <[email protected]> wrote:
>
> > > Thanks a lot ! (though you have made me feel a little dumb ;) )
>
> > > bests
>
> > > 2011/8/18 [email protected] <[email protected]>
>
> > > > On Aug 18, 9:25 am, Natxo Vergara <[email protected]> wrote:
> > > > > Hi Larry!
>
> > > > > I have the same issue as Shaheryar Ali: I'm new here in the 
> > > > > neibourhood,
> > > > and
> > > > > I'm playing a little bit with the google maps API (v3).
> > > > > Now I'm trying to get the distance between two points (two LatLng 
> > > > > points
> > > > > selected randomly by clicking on the map).
>
> > > > > I've found an old tutorial (corresponding to api v2) with the function
> > > > > "LatLng.distanceFrom", but I just can't find any thing like that for 
> > > > > v3.
> > > > > I've read the doc related to Directions, but it seems that it's a 
> > > > > little
> > > > too
> > > > > complicated just to calculate the distance between two (any two) 
> > > > > points
> > > > in
> > > > > the map.
>
> > > > > Is there something that I'm missing??
>
> > > > Have you seen the geometry library?
> > > >http://code.google.com/apis/maps/documentation/javascript/geometry.html
>
> > > >  -- Larry
>
> > > > > Thanks a lot for your time and congratulations for the phenomenal and
> > > > > amazing job you do on Google.
>
> > > > > Bests.
>
> > > > > Natxo Vergara
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "Google Maps JavaScript API v3" 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-js-api-v3?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.

Reply via email to