Problemas ao criar marcadores no Google Mapas

80 views
Skip to first unread message

Wesley Rodrigues

unread,
Mar 12, 2018, 9:23:38 AM3/12/18
to GOPHP
Eu com problemas ao criar Mapa do Google, não consigo mudar o ícone com uma condição se o type for on fica verde se não fica vermelho. Alguém pode me ajudar?

<!DOCTYPE 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>Using MySQL and PHP with Google Maps</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>

<body>
<div id="map"></div>

<script>
var customLabel = {
restaurant: {
label: 'R'
},
bar: {
label: 'B'
}
};


function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(-22.733126, -43.519338),
zoom: 17
});
var infoWindow = new google.maps.InfoWindow;

// Change this depending on the name of your PHP or XML file
downloadUrl('criar-xml.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var name = markerElem.getAttribute('name');
var address = markerElem.getAttribute('address');
var type = markerElem.getAttribute('type');
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));

var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));

var text = document.createElement('text');
text.textContent = address
infowincontent.appendChild(text);

var icon = new google.maps

var marker = new google.maps.Marker({
map: map,
position: point,
label: icon.label
});
marker.addListener('click', function() {
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
});
});
});
}



function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;

request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};

request.open('GET', url, true);
request.send(null);
}

function doNothing() {}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDGNxEDaq358Dm0dqj-Bqc-YJQWpE0kD-g&callback=initMap">
</script>
</body>
</html>

Renato de Oliveira Lucena

unread,
Mar 12, 2018, 2:56:14 PM3/12/18
to GOPHP
Nunca usei, mas um exemplo simples.

O exemplo a seguir adiciona um marcador simples a um mapa em Uluru, no centro da Austrália:

function initMap() {
  var myLatLng = {lat: -25.363, lng: 131.044};

  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: myLatLng
  });

  var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    title: 'Hello World!'
  });
}
<div id="map"></div>
/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
#map {
  height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
 <!-- Replace the value of the key parameter with your own API key. -->
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">
</script>
function initMap() {
 
var myLatLng = {lat: -25.363, lng: 131.044};


 
var map = new google.maps.Map(document.getElementById('map'), {

    zoom
: 4,
    center
: myLatLng
 
});


 
var marker = new google.maps.Marker({

    position
: myLatLng,
    map
: map,
    title
: 'Hello World!'
 
});
}

Wesley Rodrigues

unread,
Mar 12, 2018, 7:25:19 PM3/12/18
to GOPHP
O mapa esta funcionando, so tenho esse problema. Não consigo trocar o ícone.

jamario batista

unread,
Mar 13, 2018, 8:09:23 AM3/13/18
to go...@googlegroups.com

var marker = new google.maps.Marker({
      map: map,
      position: latlng,
      title: nome,

   });
Eu hospedo a imagem no servidor e chamo dentro da função  function createMarker(){}


Sent with Mailtrack

Em 12 de março de 2018 19:29, Wesley Rodrigues <wesley.sto...@gmail.com> escreveu:
O mapa esta funcionando, so tenho esse problema. Não consigo trocar o ícone.

--
Você recebeu esta mensagem porque está inscrito na Lista "GOPHP" em Grupos do Google.
Para Postar: go...@googlegroups.com
Para Sair do Grupo: gophp-unsubscribe@googlegroups.com
Link: http://groups.google.com/group/gophp?hl=pt-BR
---
Você recebeu essa mensagem porque está inscrito no grupo "GOPHP" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para gophp+unsubscribe@googlegroups.com.
Para mais opções, acesse https://groups.google.com/d/optout.



--

jamario / Analista de sistemas
jamario...@gmail.com / +55(62)91500295

Wesley Rodrigues

unread,
Mar 13, 2018, 5:24:09 PM3/13/18
to GOPHP
Ja resolvi obrigado a todos


Em segunda-feira, 12 de março de 2018 10:23:38 UTC-3, Wesley Rodrigues escreveu:
Reply all
Reply to author
Forward
0 new messages