Below is a complete, simple example of how to achieve this. For simplicity, it simply displays a square centered on latitude / longitude (0, 0) as a demonstration.
<html>
<head>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&sensor=false"></script>
<script type="text/javascript">
function init() {
var mapDiv = document.getElementById('map');
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(0.0, 0.0),
zoom: 5
});
var polygon = new google.maps.Polygon({
map: map,
paths: [
new google.maps.LatLng(-1.0, -1.0),
new google.maps.LatLng(-1.0, +1.0),
new google.maps.LatLng(+1.0, +1.0),
new google.maps.LatLng(+1.0, -1.0)
],
strokeColor: '#ff0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#ff0000',
fillOpacity: 0.5
});
google.maps.event.addListener(polygon, 'click', function (event) {
alert('clicked polygon!');
});
google.maps.event.addListener(polygon, 'mouseover', function (event) {
this.setOptions({
strokeColor: '#00ff00',
fillColor: '#00ff00'
});
});
google.maps.event.addListener(polygon, 'mouseout', function (event) {
this.setOptions({
strokeColor: '#ff0000',
fillColor: '#ff0000'
});
});
};
</script>
<style>
#map {
width: 300px;
height: 200px;
}
</style>
</head>
<body onload="init();">
<div id="map"></div>
</body>
</html>
Basically, you do the following (each dot of the dot corresponds to a numbered comment in the JavaScript code):
- Create a map.
- Draw polygons on the map for each of your neighborhoods.
- For each polygon, add a listener for click events. The listener function is called whenever your polygon is clicked. Here I just show a warning - you can do whatever you want.
- "mouseover". , . - .
- "mouseout". , . .
, . , API JavaScript Google - , . , examples, simple-polygon .