Buongiorno a tutti,
non riesco a risolvere il seguente problema. In una pagina php ho alcuni elementi. All'evento click di uno di questi elementi, tramite ajax, carico dei dati presenti in un altro file php. Quest'ultimo file, tra le varie informazioni, dovrebbe caricare anche google maps ma non essendoci l'evento onload non viene caricata (ps: se carico il file php senza ajax google maps compare correttamente). Come posso fare per risolvere il problema? grazie
posto parte del codice
File1.php
Codice PHP:
....
<head>
<script>
function InviaDati(id_photo) {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("OptionPhoto").innerHTML=this.responseText;
}
};
xmlhttp.open("GET","extractinfophoto.php?id_photo="+id_photo,true);
xmlhttp.send();
}
</script>
</head>
<body>
...
...
<div id = "OptionPhoto" class = "photo_menu"></div>
...
file2.php (extractinfophoto.php)
Codice PHP:
echo '<div id="map" style="overflow:hidden;height:200px;width:270px;">
<div id="floating-panel">
<input onclick="deleteMarkers();" type="button" value="Cancella">
</div>
<div id="gmap_canvas" style="height:200px;width:270px;">
</div>
</div>
<script>
var map;
var markers = [];
function initMap() {
var mapDiv = document.getElementById("gmap_canvas");
map = new google.maps.Map(mapDiv, {
center: {lat: 0, lng: 0},
zoom: 0,
disableDefaultUI: true
});
// This event listener will call addMarker() when the map is clicked. map.addListener("click", function(event) {
deleteMarkers();
document.getElementById("lat").value = event.latLng.lat();
document.getElementById("long").value = event.latLng.lng();
addMarker(event.latLng);
});
}
// Adds a marker to the map and push to the array.
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map,
});
markers.push(marker);
document.getElementById("id_position").value = location;
}
// Sets the map on all markers in the array.
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setMapOnAll(null);
}
// Shows any markers currently in the array.
function showMarkers() {
setMapOnAll(map);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
document.getElementById("id_position").value = "";
document.getElementById("lat").value = "";
document.getElementById("long").value ="";
}
</script><script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAdD5TnYip8P0CBLjp0FcvqTdk1TN4Pf4Q&callback=initMap"async defer></script>';