In Fusion Tables, you can directly do the SQL query you want: ORDER BY [distance] ASC|DESC http://code.google.com/intl/en/apis/fusiontables/docs/developers_reference.html#Select
The decision to use Fusion Tables is not trivial, but if you have a lot of spatial relationships to explore it might be worth considering. - Jeff On Aug 25, 6:31 am, "[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.
