Inserire Marker a Google Maps

AndrewLupin

Utente Attivo
15 Lug 2008
42
0
6
Salve a tutti, ho un sito da modificare con una Google Maps già inclusa, dovrei inserire anche il Marker ma non ci riesco. Le ho provate di tutte, ho trovato diversi esempi ma sono tutti diversi da questa. Potreste darmi una mano, sono poco pratico nello scripting.
Grazie! :)

Ecco il codice della Mappa:

HTML:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
		<script>
			var map,
				geocoder,
				address = 'Via, Citta, etc';

			function initialize() {
				var map_canvas = document.getElementById('map-canvas');

				if (map_canvas) {
					geocoder = new google.maps.Geocoder();
					geocoder.geocode( { 'address': address}, function(results, status) {
						if (status == google.maps.GeocoderStatus.OK) {
							if (map == null) {
								var mapOptions = {
									zoom: 10,
									center: results[0].geometry.location
								};

								map = new google.maps.Map(map_canvas, mapOptions);
							}
							else {
								map.setCenter(results[0].geometry.location);
							}
						} else {
							console.log('Geocode was not successful for the following reason: ' + status);
						}
					});
				}
			}

			google.maps.event.addDomListener(window, 'load', initialize);		
		</script>
 

AndrewLupin

Utente Attivo
15 Lug 2008
42
0
6
Grazie "f107", avevo già visto questo esempio ma non era lo stesso script che ho io...alla fine l'ho cambiato (cioè ho utilizzato questo che mi hai consigliato) e ho fatto prima, senza perder altro tempo.
Comunque grazie per la segnalazione! ;)
 

AndrewLupin

Utente Attivo
15 Lug 2008
42
0
6
Non so se posso scrivere qui o se devo aprire un altro post... Tra gli esempi indicati da "f107" ne ho trovato uno che fa al caso mio ed è quello in cui è presente anche una popup (info window) con delle informazioni che si possono inserire. L'unico problema è che questa popup viene fuori solo se si clicca sul marcatore della mappa, a me invece servirebbe che si aprisse subito (cioè in automatico, all'apertura della mappa) come posso fare?

L'esempio in questione è questo https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple

Il suo codice nel dettaglio:

HTML:
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Info windows</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
    <script>
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.

function initialize() {
  var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
  var mapOptions = {
    zoom: 4,
    center: myLatlng
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var contentString = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
      '<div id="bodyContent">'+
      '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
      'sandstone rock formation in the southern part of the '+
      'Northern Territory, central Australia. It lies 335 km (208 mi) '+
      'south west of the nearest large town, Alice Springs; 450 km '+
      '(280 mi) by road. Kata Tjuta and Uluru are the two major '+
      'features of the Uluru - Kata Tjuta National Park. Uluru is '+
      'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
      'Aboriginal people of the area. It has many springs, waterholes, '+
      'rock caves and ancient paintings. Uluru is listed as a World '+
      'Heritage Site.</p>'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>'+
      '</div>';

  var infowindow = new google.maps.InfoWindow({
      content: contentString
  });

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Uluru (Ayers Rock)'
  });
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>
 
Discussioni simili
Autore Titolo Forum Risposte Data
Elisacau [Contact form 7] Inserire Numero auto incrementante WordPress 1
gara1 inserire immagine di sfondo in canvas Javascript 0
FDF182 Inserire pdf in db PHP 3
otto9due Inserire o aggiornare tabella my sql controllando una coppia di valori PHP 7
Couting95 inserire dati da un file di testo in una tabella in php PHP 1
D Inserire link PHP 0
L PHPSpreadsheet inserire dati da file .xlsx/.xls su database PHP 2
P inserire due voci in un titolo post wp WordPress 1
R inserire video nel sito HTML e CSS 15
J Inserire blog wordpress in angular CMS (Content Management System) 0
A inserire variabile php colore in div html PHP 2
L inserire dati multi livello PHP 8
G Inserire una scritta Java 1
M Inserire variabile nella value di una hidden PHP 3
S Inserire foto in ogni cella di una tabella Javascript 0
G inserire dati automaticamente in mysql PHP 0
B Vorrei inserire una finestra con messaggio ad un history.back PHP 16
Shyson Inserire placeholder nel campo cerca PHP 5
M Lanciare alert se il codice fiscale è già presente nel db e lasciare la scelta di inserire all'utente PHP 42
atipika INSERIRE ICONE DOWNLOAD E STAMPA WORDPRESS WordPress 10
F Creare un set di date a seconda del frazionamento scelto da inserire in MySQL PHP 6
B inserire valori da una tabella a un altra mysql PHP 34
D [Javascript] inserire uno script in un file php Javascript 6
napuleone [HTML] type="file" inserire path di partenza HTML e CSS 4
Monital [Javascript] inserire dati estratti dal db in html fisso Javascript 1
R [WordPress] Inserire campi aggiuntivi ad un Submit Form già dato dal template (front-end) WordPress 0
M inserire i dati ottenuti da una jquery in una tabella già esistente jQuery 1
G Inserire "Leggi il resto dell'articolo" con link al post sul sito preso via RSS Email Marketing 0
M [PHP] Come inserire codice html in un ciclo while PHP 2
P [PHP] Inserire stringhe in input(text),memorizzarle e stamparle in file successivo PHP 0
J [Javascript] Inserire un caricamento con animazione prima dell'esecuzione di un'azione Javascript 1
Shyson [PHP] Inserire testo nel codice PHP 2
D Mailchimp - Possibile inserire doppia condizione per i triggers? Email Marketing 0
A [MS Access] Pulsante per inserire allegati in campo maschera MS Access 0
Shyson [HTML] Inserire nuovo font con @font-face HTML e CSS 5
Alex_70 Inserire photo in php PHP 0
D [Javascript] [HTML] Inserire slash dopo 3 numeri Javascript 5
F INSERIRE IN UN'UNICA CASELLA DI TESTO REPORT ACCESS I VALORI DELLA TABELLA DI UN'INTERA COLONNA MS Access 2
A [HTML] Come inserire google review stars nelle pagine del mio sito HTML e CSS 0
spider81man Connettersi ad un DB ed inserire dati con Javascript Javascript 3
spider81man [PHP] Inserire file .pdf in db PHP 6
P [WordPress] Inserire codice in pagina dinamica WordPress 0
A [PHP] Ciclare array multidimensionale e inserire valori in DB PHP 2
M [PHP] Inserire array nel db PHP 6
andreas88 [HTML] come inserire 3 riquadri in un unico rigo (vedere img allegata) HTML e CSS 11
G [PHP] inserire risultato di una query in una tabella PHP 3
P [Javascript] Inserire una nuova condizione in una funzione Javascript 3
G [Guida MyBB 1.8] Inserire icone accanto alle sezioni CMS (Content Management System) 0
M [wordpress-galleria immagini]Inserire classe php in html PHP 0
C Inserire dati tabella leggendo parte di altra tabella con php PHP 13

Discussioni simili