Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    residenza
    Trieste
    Messaggi
    828

    marker multipli su mappa non caricati

    scusate cinque minuti, perchè il seguente codice standard per caricare dei markers non me li fa vedere? Nell'html ho il <body onLoad="init"> ed è poi presente la API Key. Il js della mappa è il seguente:

    codice:
    google.maps.event.addDomListener(window, 'load', init);
    
        var markers = [ 
          ['Via Fonteiana', 41.8837781, 12.455300899999997],
          ['Via Ugo Arnaldi', 41.8526032, 12.467613],
          etc.
        ];
        
    function init() {
           var mapOptions = {
            zoom: 13,
            center: new google.maps.LatLng(41.9000, 12.5000), // Rome 
            disableDefaultUI: true, // controls disables
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            styles: 
            [{"featureType":"landscape","elementType":"labels","stylers":[{"visibility":"off"}]
            },{"featureType":"transit","elementType":"labels","stylers":[{"visibility":"off"}]
            },{"featureType":"poi","elementType":"labels","stylers":[{"visibility":"off"}]
            },{"featureType":"water","elementType":"labels","stylers":[{"visibility":"off"}]
            },{"featureType":"road","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"stylers":[{"hue":"#00aaff"},{"saturation":-100},{"gamma":2.15},{"lightness":12}]
            },{"featureType":"road","elementType":"labels.text.fill","stylers":[{"visibility":"on"},{"lightness":24}]
            },{"featureType":"road","elementType":"geometry","stylers":[{"lightness":57}]}]
        };
    
        var mapElement = document.getElementById('map');
    
         var map = new google.maps.Map(mapElement, mapOptions);
        var infowindow = new google.maps.InfoWindow();
        var marker, i;
        for (i = 0; i < markers.length; i++) {  
            marker = new google.maps.Marker({
                position: new google.maps.LatLng(markers[i][1], markers[i][2]),
                map: map
            });
            google.maps.event.addListener(marker, 'click', (function(marker, i) {
                return function() {
                    infowindow.setContent(markers[i][0]);
                    infowindow.open(map, marker);
                }
            })(marker, i));
        }    
    }

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    codice:
    marker = new google.maps.Marker({
       position: new google.maps.LatLng(markers[i][1], markers[i][2]),
       map: map,
       content: markers[i][0]
    });
    
    google.maps.event.addListener(marker, 'click', function(){
         infowindow.setContent(this.content);
         infowindow.open(map, this);
    });

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2007
    residenza
    Trieste
    Messaggi
    828
    grazie per il tentativo, ma sostituendo le tue righe di codice la mappa mi scompare del tutto...

  4. #4
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    avrai copiato male, riposta il codice modificato

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2007
    residenza
    Trieste
    Messaggi
    828
    a parte lo styling, la parte di codice finale ora è questa:

    codice:
        // Get the HTML DOM element that will contain your map // We are using a div with id="map" seen below in the <body>
        var mapElement = document.getElementById('map');
    
        // Create the Google Map using out element and options defined above
        var map = new google.maps.Map(mapElement, mapOptions);
        var infowindow = new google.maps.InfoWindow();
        var marker, i;
        for (i = 0; i < markers.length; i++) {  
            marker = new google.maps.Marker({
               position: new google.maps.LatLng(markers[i][1], markers[i][2]),
               map: map,
               content: markers[i][0]
            });
            google.maps.event.addListener(marker, 'click', function(){
                 infowindow.setContent(this.content);
                 infowindow.open(map, this);
            });
    }

  6. #6
    Utente di HTML.it
    Registrato dal
    Oct 2007
    residenza
    Trieste
    Messaggi
    828
    ok, la mappa era scomparsa perchè mi mancava una parentesi graffa alla fine... ora la mappa compare, ma i marker continuano a non essere presenti

    firebug mi dice: markers is not defined
    for (i = 0; i < markers.length; i++) {
    Ultima modifica di stardom; 25-04-2014 a 13:05

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.