Last active
March 15, 2016 17:20
-
-
Save courtneyphillips/7065cb107f72b94ccecb to your computer and use it in GitHub Desktop.
Example Google Maps component in Ember.js with multiple markers with corresponding unique info windows.
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
showMap(foodcarts) { | |
this.set('mapShowing', true) | |
var coordArray = []; | |
var contentArray = []; | |
var markerarray = []; | |
foodcarts.forEach(function(foodcart) { | |
coordArray.push([foodcart.get('latitude'), foodcart.get('longitude')]), | |
contentArray.push([foodcart.get('name'), foodcart.get('website')]) | |
}); | |
var container = this.$('.map-display')[0]; | |
var options = { | |
center: this.get('map').center(41.40338, 2.17403), | |
zoom: 5 | |
}; | |
var map = this.get('map').findMap(container, options); | |
var infowindow = new google.maps.InfoWindow(); | |
var marker; | |
var i = 0; | |
var j = 0; | |
for ( i = 0; i < coordArray.length; i++) { | |
marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(coordArray[i][0], coordArray[i][1]), | |
map: map, | |
title:coordArray[i][2] | |
}); | |
markerarray.push(marker); | |
}; | |
markerarray.forEach(function(marker, j){ | |
google.maps.event.addListener(marker, 'click', function() { | |
infowindow.setContent(contentArray[j-1][0] + " " + contentArray[j-1][1]); | |
infowindow.open(map, this); | |
}); | |
j++; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment