javascript - Return 3 closest locations to a users location (geolocation) and list those locations for them -
background:
i working on website/app built html/css/javascript use geolocation (google maps api) find users location (geolocation) , return them, example, top 5 closest water parks them @ location @ able navigate 1 of locations. using google fusion tables return results them.
question:
i have been able successfully...
- find users location , put marker there (using map api/geolocation)
- return 3 out of 5 locations , put markers down 3 (i used fusion tables & limited results 3)
i want able to…
- return 3 closest locations user (i.e. calculate distance users location nearest water park)
- put "sidebar" or list of 3 locations, detailing name, address, , other fields in fusion table
i made fiddle below code have far. code below fusion table query, assume need make changes in order 3 closest locations (question #1). question #2, listing locations, might use of code have in fiddle.
var base_query = { select: 'location', from: '1msmdovwlknnrtknmoef2djcc3rp_gymuen4fgnc', limit: 3 }; var ftlayer = new google.maps.fusiontableslayer({ map: map, query: $.extend({}, base_query) }); var infowindow = new google.maps.infowindow(); var marker, i; (i = 0; < base_query.length; i++) { marker = new google.maps.marker({ position: new google.maps.latlng(base_query[i][1], base_query[i][2]), map: map }); google.maps.event.addlistener(marker, 'click', (function (marker, i) { return function () { infowindow.setcontent(base_query[i][0]); infowindow.open(map, marker); } })(marker, i)); }; var signchange = function () { var options = { query: $.extend({}, base_query) }; };
http://jsfiddle.net/jamez14/brlah/2/
any appreciated. have been doing research on question time, whatever reason not able piece together. help/resources appreciated!
related 1. (2. has been answered in comments geocodezip)
use spatial_relationship in orderby
-option of base_query
.
orderby: 'st_distance(coordinates, latlng(lat,lng))
...where lat
, lng
has populated values returned navigator.geolocation
(what means must create layer or @ least set query layer in callback of navigator.geolocation.getcurrentposition
)