Je me suis retrouvé coincé dans ce problème JavaScript avec google map. Je veux afficher les informations du marqueur dans un div en dehors de la carte avec getElementById (ou toute autre recommandation que vous fournissez).afficher google carte infowindow dans un div à l'extérieur avec getElementeById
J'ai stocké l'information que je veux afficher dans le nom de la variable qu'elle n'affiche pas.
<script type="text/javascript">
var name;
var customIcons = {
restaurant: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png'
},
bar: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(48.1351, 11.5820),
zoom: 5,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html, name, downloadUrl) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
Voici où je tente de faire l'affaire
document.getElementById("mensaje").innerHTML = name;
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
<div id="map" style="width: 65%; height: 700px;float:left; display:inline;"></div>
<div id ="mensaje">
<p id="mensaje"></p>
</div>
</body>
I résolu document.getElementById ("Message") innerHTML = html; C'est html la variable que je devais afficher –