So this is working for dragging around on the map but it’s a little too sensitive (if I scroll zoom on the map it calls the function too, and also if I trigger a map marker, which changes the center of the map, it gets called)
So with this working bit of code, how can I refine this to truly only call my searchByState
function after dragging around on the map and not when zooming or triggering a marker?
google.maps.event.addListener(map,'idle',function(){
if(!this.get('dragging') && this.get('oldCenter') && this.get('oldCenter')!==this.getCenter()) {
var lat = map.getCenter().lat();
var lon = map.getCenter().lng()
searchByState(lon,lat);
}
if(!this.get('dragging')){
this.set('oldCenter',this.getCenter())
}
});
google.maps.event.addListener(map,'dragstart',function(){
this.set('dragging',true);
});
google.maps.event.addListener(map,'dragend',function(){
this.set('dragging',false);
google.maps.event.trigger(this,'idle',{});
});