Je suis en train de charger une carte avec le javascript suivant.Marqueurs dans google maps
google.load("maps", "2.x");
// Call this function when the page has been loaded
function initialize() {
var map = new google.maps.Map2(document.getElementById("map"));
map.setCenter(new google.maps.LatLng(52,-3), 13);
var point = new google.maps.LatLng(52,-3);
var marker = new google.maps.Marker(point, {draggable: true});
map.addOverlay(marker);
google.maps.Event.addListener(marker, "dragend", function(latlng) {
marker.openInfoWindowHtml("Dragged to <br>" + latlng);
});
}
google.setOnLoadCallback(initialize);
Plus tard, je veux ajouter d'autres marqueurs à la carte, après que l'utilisateur a entré un (lat, lon) paire Comment puis-je accéder à la variable map
que j'ai créé dans la fonction initialize
?
Malgré l'utilisation de variables globales, c'est un meilleur moyen d'encapsuler 'map', par ex. dans un modèle de module. –