CHALLENGE
var shoppingCenters = [{
id: 0,
name: 'Leclerc',
location: 'Paris,France',
address:'Boulevard Rahal El Meskini Casablanca Maroc',
]
},
{
/*Malls B*/
id: 1,
name: 'Carefour',
location: 'Toulouse, France',
address:'Angle Zaid Ou Hmad Rue Sidi Belyout, Casablanca Maroc',
}];
CUSTOM CONTROLLER
var address = "";
var id_mall ="";
var shoppingCenters = ShoppingCenters.all();
for (var i = 0; i < shoppingCenters.length; i++) {
center = shoppingCenters[i];
addMarker(center);
}
function addMarker(address) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 14,
center: latlng
}
id = center.id;
address = center.address;
console.debug(address);
map = new google.maps.Map(document.getElementById('map'), mapOptions);
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
title: 'shopping center',
position: results[0].geometry.location,
url:'#/tab/malls/'+id
});
google.maps.event.addListener(marker, 'click', function() {
window.location.href=marker.url;
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
When clicking on a marker, it shows /tab/malls/1 even though there are two markers and should display /tab/malls/0 as well. I'm unable to find a solution.
Seeking assistance, thank you.