0

I have a number of markers displayed on a Google map. Markers are loaded from a dB and added to the array markers:

var markers = [
{
    "ID": "99",
    "title": "Ut vestibulum tincidunt consectetur vestibulum.",
    "coords": "45.6496292, 13.7740742",
},
{
    "ID": "259",
    "title": "Faucibus tempus vivamus scelerisque vestibulum.",
    "coords": "45.6455002, 13.7595193",
},
{
    "ID": "261",
    "title": "Taciti ante scelerisque consequat inceptos nunc.",
    "coords": "45.6455002, 13.7595193",
}
];

By clicking a marker infoWindow is popped up correctly:

gooole.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(this.content);
    infowindow.open(map, this);
}); 

Inside infoWindow there's a link that when clicked pops up a boostrap dialog that permits to edit the content of infoWindow. The fields of this dialog are populated via Ajax (jQuery). When a field is changed and changes are saved, the dialog closes and the changed data is immediately shown in the infoWindow that in the meanwhile stayed opened.

Up to now everything works fine.

The issue I'm working on without success is that when I close the 'edited' infoWindow or I click on an other marker so that the 'edited' infoWindow closes and then I reopen the previous 'edited' infoWindow the changes are not shown.

I thought I could simply change the value in the markers array for example like this:

setTitle(id, "This is the new title");

function setTitle(id, newtitle) 
    for (var i = 0; i < markers.length; i++) {
        if (markers[i]["ID"] === id) {
            markers[i]["title"] = newtitle;
            return;
        }
    }
}

and see it 'react' dinamically in the infoWindow but it does not. The markers array is built in index.php while the map and the dialog are loaded via ajax separately (map.php and edit.php). I placed markers in index.php so I'm sure it is accessible and in fact for example

 console.log(markers[13]["title"]);

displays correctly any change, but this change is not 'preserved' to be shown in the 'edited' infoWindow .

Nicero
  • 4,181
  • 6
  • 30
  • 52
  • i think you need to redraw the map, may be triggering a resize event will help `google.maps.event.trigger(MapInstance,'resize')` . https://stackoverflow.com/questions/18426083/how-do-i-force-redraw-with-google-maps-api-v3-0 – Nidhin Chandran Jun 21 '17 at 08:55
  • After clicking on a marker you set the content of info window as `infowindow.setContent(this.content);`. Do you update the value of `this.content` after saving the data? – xomena Jun 23 '17 at 11:02

0 Answers0