javascript - Google Places API rankBy -
i'm coding js app things
find location(i did this) find specified atm(well didn't figure how find around radius) list found atms , sort them distance
for need rankby don't know how use it.i looked on internet,where talks no 1 don't show how use.
does can mi set radius , in radius show atms , sort them distance?
here code
<!doctype html> <html> <head> <meta charset="utf-8"> <title>marker animations</title> <style> /* set map height explicitly define size of div * element contains map. */ #map { height: 100%; } /* optional: makes sample page fill window. */ html, body { height: 100%; margin: 0; padding: 0; } </style> </head> <body> <div id="map"></div> <script> function initmap() { var map, infowindow,service,infowindow1; map = new google.maps.map(document.getelementbyid('map'), { center: {lat: -34.397, lng: 150.644}, zoom: 12 }); infowindow = new google.maps.infowindow; // try html5 geolocation. if (navigator.geolocation) { navigator.geolocation.getcurrentposition(function (position) { var pos = { lat: position.coords.latitude, lng: position.coords.longitude }; infowindow.open(map); map.setcenter(pos); var marker = new google.maps.marker({ map: map, position: pos, draggable: true, animation: google.maps.animation.drop, }); marker.addlistener('click', togglebounce); function togglebounce() { if (marker.getanimation() !== null) { marker.setanimation(null); } else { marker.setanimation(google.maps.animation.bounce); } } }, function () { handlelocationerror(true, infowindow, map.getcenter()); }); } else { // browser doesn't support geolocation handlelocationerror(false, infowindow, map.getcenter()); } function handlelocationerror(browserhasgeolocation, infowindow, pos) { infowindow.setposition(pos); infowindow.setcontent(browserhasgeolocation ? 'error: geolocation service failed.' : 'error: browser doesn\'t support geolocation.'); infowindow.open(map); } infowindow1 = new google.maps.infowindow; service = new google.maps.places.placesservice(map); map.addlistener('idle', performsearch); function performsearch() { var request = { bounds: map.getbounds(), keyword: 'telenor atm', }; service.radarsearch(request, callback); } function callback(results, status) { if (status !== google.maps.places.placesservicestatus.ok) { console.error(status); return; } (var = 0, result; result = results[i]; i++) { addmarker(result); } } function addmarker(place) { var marker = new google.maps.marker({ map: map, position: place.geometry.location, icon: { url: 'https://developers.google.com/maps/documentation/javascript/images/circle.png', anchor: new google.maps.point(10, 10), scaledsize: new google.maps.size(30, 37) } }); google.maps.event.addlistener(marker, 'click', function () { service.getdetails(place, function (result, status) { if (status !== google.maps.places.placesservicestatus.ok) { console.error(status); return; } infowindow1.setcontent(result.name); infowindow1.open(map,marker); }); }); } } </script> <script src="https://maps.googleapis.com/maps/api/js?key=aizasycw8grr1itjdx4f-rvpkbsetftu32xo2p0&callback=initmap&libraries=places,visualization" async defer></script> </body> </html>
Comments
Post a Comment