Created
February 24, 2016 13:37
-
-
Save Cathon/9f650b5b722abc28e715 to your computer and use it in GitHub Desktop.
Google map Js API infowindow array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map; | |
var infowindow; | |
var locations = [ | |
{lat: 52.511, lng: 13.447}, | |
{lat: 52.549, lng: 13.422}, | |
{lat: 52.497, lng: 13.396}, | |
{lat: 52.517, lng: 13.394} | |
]; | |
var contents = [ | |
"aaa", | |
"bbb", | |
"ccc", | |
"ddd" | |
]; | |
function initMap() { | |
var latlng = {lat: 52.511, lng: 13.447}; | |
var mapOptions = { | |
center: latlng, | |
zoom: 10 | |
}; | |
map = new google.maps.Map(document.getElementById('map'), mapOptions); | |
infowindow = new google.maps.InfoWindow(); | |
for (var i = 0; i < locations.length; i++) { | |
createMarker(locations[i], contents[i]); | |
} | |
} | |
function createMarker(location, content) { | |
var marker = new google.maps.Marker({ | |
position: location, | |
map: map | |
}); | |
marker.addListener('click', function() { | |
infowindow.setContent(content); | |
infowindow.open(map, this); | |
}); | |
} | |
// https://stackoverflow.com/questions/12087212/an-array-of-infowindow-in-google-maps-api | |
// https://developers.google.com/maps/articles/phpsqlsearch_v3#creating-the-map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment