google maps marker

rikka@3

Nuovo Utente
13 Nov 2013
6
0
0
Salve sto cercando di creare una mappa con dei markers partendo da degli indirizzi
ma ho un problema su tutti i marker che creo mi riporta come tag lo stesso .. ovvero l'ultima descrizione che ho caricato nell'array e non capisco il motivo ?!
vi riporto sotto lo script
HTML:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  var geocoder;
  var map;
  var tag =""; 
  var address ="";
  var indirizzo = [ 'San Diego, CA', 'Firenze, Italia','Cortona, Italia','Perugia, Italia','Roma, Italia'		];
  var descrizione = [ '1111', '222222','333333','444444','55555'		];  
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
    mapTypeControl: true,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
    navigationControl: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    for (var i = 0; i < indirizzo.length; i++) { 		address=indirizzo[i];       tag = descrizione[i];
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
          map.setCenter(results[0].geometry.location);

            var infowindow = new google.maps.InfoWindow(
                { content: '<b>'+tag+'</b>',
                  size: new google.maps.Size(150,50)
                });
    
            var marker = new google.maps.Marker({
                position: results[0].geometry.location,
                map: map, 
                title:tag
            }); 
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);
            });

          } else {
            alert("No results found");
          }
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
  }
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
 <div id="map_canvas" style="width:100%; height:100%">
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-162157-1";
urchinTracker();
</script>
</body>
</html>
 
Ultima modifica di un moderatore:

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Ciao, non ho capito il motivo ma potresti risolvere incrementando un'altra variabile all'interno della funzione geocode() e usarla poi per prendere la descrizione dall'array
Codice:
y = 0;
 for (i in indirizzo) {

   // etc etc

tag = descrizione[y];
var marker = new google.maps.Marker({
     position: results[0].geometry.location,
     map: map, 
     title: tag
 }); 
 y++;

// etc etc
 

rikka@3

Nuovo Utente
13 Nov 2013
6
0
0
Ciao, non ho capito il motivo ma potresti risolvere incrementando un'altra variabile all'interno della funzione geocode() e usarla poi per prendere la descrizione dall'array
Codice:
y = 0;
 for (i in indirizzo) {

   // etc etc

tag = descrizione[y];
var marker = new google.maps.Marker({
     position: results[0].geometry.location,
     map: map, 
     title: tag
 }); 
 y++;

// etc etc


scusa l'ignoranza .. ma cosi ho un for dentro ad un altro.. non mi moltiplica esponenzialmente l'inserimento dei marker?
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
il cilco è uno solo, ho postato solo le porzioni di codice interessate, questo è lo script intero
Codice:
<script type="text/javascript">
            var geocoder;
            var map;
            var tag =""; 
            var address ="";
            var indirizzo = [ 'San Diego, CA', 'Firenze, Italia','Cortona, Italia','Perugia, Italia','Roma, Italia'];
            var descrizione = [ '1111', '222222','333333','444444','55555'];  
            function initialize() {
                geocoder = new google.maps.Geocoder();
                var latlng = new google.maps.LatLng(-34.397, 150.644);
                var myOptions = {
                    zoom: 8,
                    center: latlng,
                    mapTypeControl: true,
                    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
                    navigationControl: true,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                y = 0;
                for (i in indirizzo) { 		
                    address=indirizzo[i];      
                    
                    geocoder.geocode( { 'address': address}, function(results, status) {
                        
                        if (status == google.maps.GeocoderStatus.OK) {
                            if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                                map.setCenter(results[0].geometry.location);

                                var infowindow = new google.maps.InfoWindow(
                                { content: '<b>'+ tag +'</b>',
                                    size: new google.maps.Size(150,50)
                                });
                                tag = descrizione[y];
                                var marker = new google.maps.Marker({
                                    position: results[0].geometry.location,
                                    map: map, 
                                    title: tag
                                }); 
                                y++;
                                google.maps.event.addListener(marker, 'click', function() {
                                    infowindow.open(map,marker);
                                });

                            } else {
                                alert("No results found");
                            }
                        } else {
                            alert("Geocode was not successful for the following reason: " + status);
                        }
                    });
                }
            }
        </script>
 

rikka@3

Nuovo Utente
13 Nov 2013
6
0
0
GRAZIE MILLE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

visto che sei disponibile ( cosa rara :) )
ti chiedo un'altra cosa..
adesso la nuvoletta sopra il marker mi viene solo o con il tag quando ci vado sopra oppure facendo click sul marker..
se io la volessi visualizzata fissa sempre senza bisogno di passarci o cliccarci come devo fare?

grazie ancoira
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Basta aggiunger questo nel punto giusto
Codice:
infowindow.open(map,marker);
In quello di prima avevo posizionato male le altre istruzioni
provalo cosi
HTML:
<script type="text/javascript">
            var geocoder;
            var map;
            var tag =""; 
            var address ="";
            var indirizzo = [ 'San Diego, CA', 'Firenze, Italia','Cortona, Italia','Perugia, Italia','Roma, Italia'];
            var descrizione = [ '1111', '222222','333333','444444','55555'];  
            function initialize() {
                geocoder = new google.maps.Geocoder();
                var latlng = new google.maps.LatLng(-34.397, 150.644);
                var myOptions = {
                    zoom: 8,
                    center: latlng,
                    mapTypeControl: true,
                    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
                    navigationControl: true,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                y = 0;
                for (i in indirizzo) { 		
                    address=indirizzo[i];      
                    
                    geocoder.geocode( { 'address': address}, function(results, status) {
                        
                        if (status == google.maps.GeocoderStatus.OK) {
                            if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                                map.setCenter(results[0].geometry.location);                                
                                tag = descrizione[y];                                
                                var infowindow = new google.maps.InfoWindow(
                                { content: '<b>'+ tag +'</b>',
                                    size: new google.maps.Size(150,50)
                                });                                
                                var marker = new google.maps.Marker({
                                    position: results[0].geometry.location,
                                    map: map, 
                                    title: tag
                                });                                 
                                infowindow.open(map,marker);
                                google.maps.event.addListener(marker, 'click', function() {
                                    infowindow.open(map,marker);
                                });
                                y++;
                            } else {
                                alert("No results found");
                            }
                        } else {
                            alert("Geocode was not successful for the following reason: " + status);
                        }
                    });
                }
            }
        </script>
 

rikka@3

Nuovo Utente
13 Nov 2013
6
0
0
altro problemino

ciao ho cantato vittoria troppo presto!!!!!

adesso mi visualizza tutto correttamente nuvoletta compresa.. ho un solo piccolissimo problema che mi visualizza massimo 12 marker dopo mi restituisce questo errore

geocode not successful -reason OVER_QUERY_LIMIT

ho provato a mettere uno sleep(2) nel mezzo ma non cambia nulla..
hai qualche suggerimento?:book:
 

rikka@3

Nuovo Utente
13 Nov 2013
6
0
0
ancora problemi

Basta aggiunger questo nel punto giusto
Codice:
infowindow.open(map,marker);
In quello di prima avevo posizionato male le altre istruzioni
provalo cosi
HTML:
<script type="text/javascript">
            var geocoder;
            var map;
            var tag =""; 
            var address ="";
            var indirizzo = [ 'San Diego, CA', 'Firenze, Italia','Cortona, Italia','Perugia, Italia','Roma, Italia'];
            var descrizione = [ '1111', '222222','333333','444444','55555'];  
            function initialize() {
                geocoder = new google.maps.Geocoder();
                var latlng = new google.maps.LatLng(-34.397, 150.644);
                var myOptions = {
                    zoom: 8,
                    center: latlng,
                    mapTypeControl: true,
                    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
                    navigationControl: true,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                y = 0;
                for (i in indirizzo) { 		
                    address=indirizzo[i];      
                    
                    geocoder.geocode( { 'address': address}, function(results, status) {
                        
                        if (status == google.maps.GeocoderStatus.OK) {
                            if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                                map.setCenter(results[0].geometry.location);                                
                                tag = descrizione[y];                                
                                var infowindow = new google.maps.InfoWindow(
                                { content: '<b>'+ tag +'</b>',
                                    size: new google.maps.Size(150,50)
                                });                                
                                var marker = new google.maps.Marker({
                                    position: results[0].geometry.location,
                                    map: map, 
                                    title: tag
                                });                                 
                                infowindow.open(map,marker);
                                google.maps.event.addListener(marker, 'click', function() {
                                    infowindow.open(map,marker);
                                });
                                y++;
                            } else {
                                alert("No results found");
                            }
                        } else {
                            alert("Geocode was not successful for the following reason: " + status);
                        }
                    });
                }
            }
        </script>



ciao ho cantato vittoria troppo presto!!!!!

adesso mi visualizza tutto correttamente nuvoletta compresa.. ho un solo piccolissimo problema che mi visualizza massimo 12 marker dopo mi restituisce questo errore

geocode not successful -reason OVER_QUERY_LIMIT

ho provato a mettere uno sleep(2) nel mezzo ma non cambia nulla..
hai qualche suggerimento?
 
Discussioni simili
Autore Titolo Forum Risposte Data
maxnegri Icon Multi Marker Personalizzate Google Maps Javascript 0
A [Javascript] Mostrare un marker se è vicino al risultato di ricerca con google maps Javascript 3
ecosito Google Maps: Centrare il marker ed editare il fumetto PHP 1
A Rimuovere il Marker di Google Maps Javascript 0
A Inserire Marker a Google Maps Javascript 3
felino Google Maps - Marker con la stessa latitudine e longitudine HTML e CSS 1
S Assegnare link ad un marker di google maps Javascript 2
R Google maps : marker e cerchio... non funziona Javascript 2
M info marker google maps con cicli Javascript 0
M Questa pagina non carica correttamente Google Maps: aiuto!! HTML e CSS 1
B "Scheda" di Google che appare su Google Maps Discussioni Varie 0
Tommy03 [PHP] Iframe Google Maps PHP 1
syndr0m3 [WordPress] Google Maps WordPress 0
A [HTML] alternative a Google Maps - aggiornamento condizioni giugno 2018 HTML e CSS 6
T [Javascript] Google maps con puntatore animato funziona solo in locale Javascript 1
T Api google maps Sviluppo app per Android 1
simgia [Javascript] Google maps help! Javascript 1
H Condivisione posizione Google Maps e navigazione automatica Sviluppo app per Android 0
booklisa scrollwheel: true Wordpress e google maps CMS (Content Management System) 0
booklisa Wordpress e cartina google maps WordPress 0
felino Indicizzazione e Google Maps SEO e Posizionamento 1
base90 [PHP] [HTML] Google Maps con due indirizzi PHP 12
M [Javascript] Percorso predefinito Google Maps Javascript 0
S Google Maps e XMLHttpRequest Javascript 0
R Javascript e html - estrazione EXIF da jpg con link per geolocalizzazione google maps Javascript 0
A Image Overlays Google Maps App Inventor 2 Presentati al Forum 0
Francesco Polese Segnaposto Google Maps dinamico PHP 5
L Google maps aggiunta makers da php Javascript 4
M funzioni google maps sovrapposizione markers Javascript 0
M calcola percorso google maps Javascript 0
M Caricare più google maps con un ciclo Javascript 1
K App che utilizzi le api di google maps Sviluppo app per Android 1
F Parola chiave posizionata su Google Maps è posizionamento? SEO e Posizionamento 10
A [Java] form con indirizzi presi da google maps Java 0
felino Google Maps - Custom Street View panoramas HTML e CSS 1
S google maps Javascript 0
M Script Google Maps per ricavare coordinate di un indirizzo PHP 0
A Google maps API v2 in app Android Sviluppo app per Android 2
M Passare dati a google maps PHP 36
T [Javascript] [RISOLTO] Problema con Google Maps e "Zero_Results" Javascript 11
T Problema con Google Maps e "Zero_Results" Classic ASP 2
F Google maps: Assegnare icone personalizzate a markers estratti da mysql. Javascript 3
P Google Maps + Form Javascript 1
G Filtrare risultati Google Maps PHP 1
ivarello Search Box in google maps Javascript 0
I Google Maps HTML e CSS 14
P Mostrare punti interesse du una mappa di google maps Javascript 1
P Google maps... help Javascript 3
borgo italia google maps jQuery 4
Sargon Google maps mysql php PHP 3

Discussioni simili