Whoops had an extra line left in there from some debugging. Try this:
/**
* @param {google.maps.LatLng} newLatLng
* @returns {number}
*/
google.maps.LatLng.prototype.distanceFrom = function(newLatLng) {
var lat1 = this.lat() * Math.PI / 180.0;
var lat2 = newLatLng.lat() * Math.PI / 180.0;
var lngDiff = (newLatLng.lng() - this.lng()) * Math.PI / 180.0;
return Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1)
* Math.cos(lat2) * Math.cos(lngDiff)) * 20902231.0029;
}
Chad Killingsworth
On Feb 24, 7:00 pm, Chad Killingsworth
<[email protected]> wrote:
> Until they are part of the API, you can add them yourself. The
> following code will add a distanceFrom prototype to LatLng objects and
> calculate the distance using the spherical law of cosines.
>
> /**
> * @param {google.maps.LatLng} newLatLng
> * @returns {number}
> */
> google.maps.LatLng.prototype.distanceFrom = function(newLatLng) {
> var lat1 = this.lat() * Math.PI / 180.0;
> var lat2 = newLatLng.lat() * Math.PI / 180.0;
> var lngDiff = (newLatLng.lng() - this.lng()) * Math.PI / 180.0;
> var a = Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1)
> * Math.cos(lat2) * Math.cos(lngDiff)) * 20902231.0029; ;
> return Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1)
> * Math.cos(lat2) * Math.cos(lngDiff)) * 20902231.0029;
>
> }
>
> Seehttp://www.movable-type.co.uk/scripts/latlong.htmlfor reference.
>
> Chad Killingsworth
>
> On Feb 24, 5:01 am, MacBoy <[email protected]> wrote:
>
> > Please make it clear that, I am not asking about Directions service.
> > This question is about the distance between to point in the world.
>
> > In v2, there is a distanceFrom Methods under class GLatLng, but I
> > can't find it in v3, is there similar function available? is this
> > Methods going to appear in v3 soon?
>
> > Thanks,
> > Leonardo
>
> > v2
> > distanceFromhttp://code.google.com/intl/en/apis/maps/documentation/reference.html...
--
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.