Making AJAX requests when a Map is changed by the user with the Google Maps Javascript API -


I am creating a website with ASP.NET MVC where a feature using Google Maps is a Google Map Display some points on the Javascript API Since I have so many digits, I do not want to bring them all; Rather, I just want to see those people who are in the current visual field that the user is viewing on the map (the bounding box)

To do this, I give an AJAX request to my C # code which points to all the points inside a certain boundary box. However, any event handler is required to be created in any way, whenever the map is pinned or zoomed by the user.

How can I find out if I point or zoom the map using the Google Maps JavaScript API?

Thanks in advance

Update: I know that I have to implement an event listener, can someone tell me in the list of events that I can use for a map object? Click is one of those incidents, but which are related to zooming and panning?

It looks like you're looking for an inactive event:

This event is removed when the map becomes inactive after panning or zooming.

Example:

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Google Maps Event & lt; / Title & gt; & Lt; Script src = "http://maps.google.com/maps/api/js?sensor=false" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div id = "map" style = "width: 500px; height: 400px;" & Gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" & gt; Var map = new google.maps.Map (document.getElementById ('map'), {zoom: 10, center: new google.maps.LatLng (-33.92, 151.25), type the map: google.maps.MapTypeId.ROADMAP }); Google.maps.event.addListener (map, 'inactive', function () {var bounds = map.getBounds (); console.log ('Northeast:' + bounds.getNorthEast (). Lat () + '' + Bounds .getNorthEast () .lng (); console.log ('south west:' + bounds.getSouthWest (.) Lat () + '+ bounds.getSouthWest () .lng ()); // your AJAX code here On ...     }); & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

In addition, you can find a list of all the events exported by the google.maps.Map object from the API reference:


Comments