Google Maps - Identical values in all info windows -
this question has answer here:
like many other people i'm finding identical values within info windows. alas, i've been using other posts in attempt troubleshoot. no luck.
issue: each of infowindows shows same values. sigh.
any appreciated.
var map; function initialize() { var markers = []; var mapoptions = { zoom: 4, scrollwheel: false, streetviewcontrol: true, pancontrol: true, zoomcontrol: true, zoomcontroloptions: { style: google.maps.zoomcontrolstyle.large // position: google.maps.controlposition.left_center }, center: new google.maps.latlng(-25.898854, 134.091377) }; map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); setmarkers(map, beaches); infowindow = new google.maps.infowindow({ content: "loading..." }); var input = /** @type {htmlinputelement} */( document.getelementbyid('pac-input')); map.controls[google.maps.controlposition.top_left].push(input); var searchbox = new google.maps.places.searchbox( /** @type {htmlinputelement} */(input)); google.maps.event.addlistener(searchbox, 'places_changed', function() { var places = searchbox.getplaces(); (var = 0, marker; marker = markers[i]; i++) { marker.setmap(null); } markers = []; var bounds = new google.maps.latlngbounds(); (var = 0, place; place = places[i]; i++) { var image = { //url: 'assets/img/icon_pin.png', //size: new google.maps.size(40, 52), //origin: new google.maps.point(0, 0), //anchor: new google.maps.point(26, 20) }; var marker = new google.maps.marker({ map: map, icon: image, title: place.name, position: place.geometry.location }); markers.push(marker); bounds.extend(place.geometry.location); } map.fitbounds(bounds); }); google.maps.event.addlistener(map, 'bounds_changed', function() { var bounds = map.getbounds(); searchbox.setbounds(bounds); }); } var beaches = [ ['auburn', -33.847113, 151.04485, 1, '100', 'parramatta', 'road', 'auburn', 'nsw', '2144', '02 7837 9800', '06:00 - 22:00', '06:00 - 22:00'], ['balgowlah platinum', -33.79284, 151.26376, 2, 'shop 67, 197-215', 'condamine', 'street', 'balgowlah', 'nsw', '2093', '1300 55 77 99', '06:00 - 21:30', '06:00 - 21:30'], ['bankstown', -33.931208, 151.02895, 3, 'unit 1-2, 9', 'chapel', 'street', 'south bankstown', 'nsw', '2200', '02 8707 4700', '06:00 - 22:00', '06:00 - 22:00'] ['bayside', -37.954768, 145.03128, 4, '241 - 245', 'bay', 'road', 'highett', 'vic', '3190', '03 9559 7400', '06:00 - 22:00', '06:00 - 22:00'] ]; function setmarkers(map, locations) { var image = { url: 'assets/img/icon_pin.png', size: new google.maps.size(40, 52), origin: new google.maps.point(0,0), anchor: new google.maps.point(26, 20) }; var shape = { coord: [1, 1, 1, 52, 40, 52, 40 , 1], type: 'poly' }; (var = 0; < locations.length; i++) { var beach = locations[i]; var mylatlng = new google.maps.latlng(beach[1], beach[2]); var marker = new google.maps.marker({ position: mylatlng, map: map, icon: image, shape: shape }); var contentstring = '<div class="sitenotice"><h4>'+beach[0]+'</h4><p>'+beach[4]+' '+beach[5]+' '+beach[6]+' '+beach[7]+', '+beach[8]+', '+beach[9]+'</p><p><strong>contact:</strong> '+beach[10]+'</p><p><strong>opening hours:</strong><br><span>monday:</span> '+beach[11]+'<br><span>tuesday:</span> '+beach[11]+'<br><span>wednesday:</span> '+beach[11]+'<br><span>thursday</span>: '+beach[11]+'<br><span>friday:</span> '+beach[11]+'<br><span>saturday</span>: '+beach[11]+'<br><span>sunday:</span> '+beach[11]+'</p></div>'; google.maps.event.addlistener(marker, "click", function () { infowindow.setcontent(contentstring); infowindow.open(map, this); }); } } google.maps.event.adddomlistener(window, 'load', initialize);
i had create array of info markers hold data.
var markers = []; function addmaplocation(map, lat, long, title, message) { var locationlatlong = new google.maps.latlng(lat, long); var locationmarker = new google.maps.marker({ position: locationlatlong, map: map, title: title.trim() }); attachmessage(locationmarker, message); markers.push(locationmarker); } function attachmessage(marker, message) { var locationinfo = new google.maps.infowindow({ content: message }); google.maps.event.addlistener(marker, 'click', function () { locationinfo.open(marker.get('map'), marker); }); }
Comments
Post a Comment