yes i save the distance:

        myMarker.distance = distance;

And now i want to sort by this value, how is it possible?

Thanks:)

On 25 août, 15:31, "[email protected]" <[email protected]>
wrote:
> On Aug 25, 6:15 am, superscral <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > I have a Google Maps and I get all markers that are close to a
> > location (lat, lng). This point is OK.
>
> > Now i want to sort theses markers, like in SQL we can do a "order by
> > distance ASC" for example.
>
> > I saw in javascript have a method call sort() which can sort some
> > numbers asc or desc for example.
>
> > markers have some informations: name, title, gender, city,
> > postcode ...
>
> > my code:
>
> >  var nbMeters = 50000;
>
> > for (var i = 0; i < markers.length; i++) {
> >         var myMarker = markers[i];
>
> >          coord2 = new google.maps.LatLng(myMarker.lat, myMarker.lng);
> >         var distance =
> > google.maps.geometry.spherical.computeDistanceBetween(coords,
> > coords2);
>
> >   if(distance <= nbMeters) {
>
> >      alert(myMarker.name);
> >     //OK my marker is close the variable coords, good !
> >     //But how to know which marker is the closer, which is the second,
> > the third ... and the less closer ??
>
> You are calculating the distance, save it in your array and sort by
> that value.
>
>   -- Larry
>
>
>
>
>
>
>
>
>
> >   }
>
> > }
>
> > Have you an idea?
>
> > Thanks

-- 
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