Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Prove Yourself

Adicionar mais de um marcador no google maps

Recommended Posts

Bom dia, estou tentando adicionar mais de um marcador (infowindow) no meu mapa, mas não estou conseguindo. Sempre aparece o último marcador adicionado.

Segue o código

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
	<title>Google Maps JavaScript API Example</title>
	<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA0oe3VGZFpTVFuJGT5tAt4hSmBkU_cBq-aaQh2Yav2TFh5tQTYBTrJyEu-KnPBsInCglM4jcYZ4baSg"
	  type="text/javascript"></script>
	<script type="text/javascript">

	//<![CDATA[

	function load() {
	  if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		
		map.setCenter(new GLatLng(-27.508271, -50.427246), 6);
		map.openInfoWindow(map.getCenter(), document.createTextNode("Santa Catarina"));
		
		var marker = new GMarker(new GLatLng(-27.535065, -48.549957), document.createTextNode("Florianópolis"));
		
		map.addOverlay(marker);
	  }
	}

	//]]>
	</script>
  </head>
  <body onload="load()" onunload="GUnload()">
	<div id="map" style="width: 500px; height: 300px"></div>
  </body>
</html>
Podem me ajudar? Obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Um exemplo:

 

 

var point = new GLatLng(43.65654,-79.90138); 
	  var marker = createMarker(point,'<div style="width:240px">Janelinha de info <a href="http://forum.imasters.com.br">com link<\/a>.<\/div>')
	  map.addOverlay(marker);
 
	  var point = new GLatLng(43.91892,-78.89231);
	  var marker = createMarker(point,'Outra janelinha<br>de informações')
	  map.addOverlay(marker);
 
	  var point = new GLatLng(43.82589,-79.10040);
	  var marker = createMarker(point,'Mais uma! E por aí vai...')
	  map.addOverlay(marker);

Não inclui todos de uma vez! Você vai criando e inserindo, entendeu?

 

Abrax! ^_^

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu estou com um problema parecido, quero pegar as latitudes e longitudes com o location e add marcadores no mapa.

Estou utilizando um loop pra isso, mas não está funcionando.

Alguém tem alguma idéia?

Segue o código:

 

for(i in locais){
    geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': locais[i]}, function(results, status) {
	if (status == google.maps.GeocoderStatus.OK){
    	 var marker = new google.maps.Marker({
	 map: map,
	 position: new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()),
	 draggable: true,
	 title: locais[i]
       });
	var infowindow = new google.maps.InfoWindow(), marker;
	map.setCenter(new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()));
	map.setZoom(2);
	map.addOverlay(marker);
	google.maps.event.addListener(marker, 'click', (function(marker, i) {
	return function() {
	  infowindow.setContent("Conteúdo do marcador 1.");
	  infowindow.open(map, marker);
	}
	})(marker));
}			});
		}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.