Google Maps - search within bounds / viewport -
i want search return hits within map/viewport. zoom in on britain , search london map bounds, response return 3 hits in us. how limit search?
code:
function codeaddress(){ geocoder = new google.maps.geocoder(); var address = document.getelementbyid("inputaddress").value; var bounds = map.getbounds(); geocoder.geocode({address: address, bounds: bounds}, function(results, status){ if(status == google.maps.geocoderstatus.ok){ // put markers on each hit } }); }
i'm assuming limiting results trying plot relevant markers right?
so instead of limiting search directly, can try indirect approach. if(status == google.maps.geocoderstatus.ok){ // put markers on each hit }
in if loop can use method called contains() on bounds of map, so
if(status == google.maps.geocoderstatus.ok) { if(map.getbounds().contains(result-location)) { // put markers on each hit } }
where result-location location of result returned geocode request. way plot markers within maps bounds.
hope helps.
Comments
Post a Comment