
06/01/2016, 11:04
|
| | Fecha de Ingreso: enero-2012
Mensajes: 224
Antigüedad: 13 años, 2 meses Puntos: 1 | |
google maps - mysql tablas relacionadas hola muchachos como están tengo un problema con un código de google maps que uso para mostrar marcadores
los datos los tomo de una tabla mysql , esta esta vinculada a otra tabla que se llama tipo_marcador que tiene la dirección url de la imagen del icono a mostrar en el mapa
tengo un problema para mostrar el icono según el tipo de marcador, se me repite siempre el primer registro , alguno me podría echar una mano gracias
Código:
$a= array();
$i=0;
$sql= $con->query('SELECT a.* , b.* FROM marcadores a , tipo_marcador b WHERE a.tipo = b.id');
while( $row =mysqli_fetch_array($sql)){
$b=array();
$b[]= utf8_encode($row["nombre"]);
$b[]=$row["lat"];
$b[]=$row["lng"];
$b[]=$row["tipo"];
$b[]=$row["descripcion"];
$b[]= ($row["id"]);
$icono= ($row["icono"]);
$a[$i]=$b;
$i++;
}
?>
<script type="text/javascript">
var map;
var Markers = {};
var infowindow;
var locations = <? echo json_encode($a); ?>;
var origin = new google.maps.LatLng(locations[0][1], locations[0][2]);
function initialize() {
var mapOptions = {
zoom: 13,
center: origin
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
infowindow = new google.maps.InfoWindow();
var image = {
url: '<?php echo $icono ; ?>',
// This marker is 20 pixels wide by 32 pixels high.
size: new google.maps.Size(20, 32),
// The origin for this image is (0, 0).
origin: new google.maps.Point(0, 0),
// The anchor for this image is the base of the flagpole at (0, 32).
anchor: new google.maps.Point(0, 32)
};
for(i=0; i<locations.length; i++) {
var position = new google.maps.LatLng(locations[i][1], locations[i][2]);
var marker = new google.maps.Marker({
position: position,
map: map,
icon: image,
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading" style="font-size:12px;">'+ locations[i][0] +'</h1>'+
'<div id="bodyContent">'+
'<p>'+ locations[i][4]+'</p>'+
'<a href="detalle_marcador.php?id='+ locations[i][5]+'"> <p> Ver Detalle </p> </a>'+
'</div>'+
'</div>';
infowindow.setContent(contentString);
infowindow.setOptions({maxWidth: 400});
infowindow.open(map, marker);
}
}) (marker, i));
Markers[locations[i][0]] = marker;
}
locate(0);
}
function locate(marker_id) {
var myMarker = Markers[marker_id];
var markerPosition = myMarker.getPosition();
map.setCenter(markerPosition);
google.maps.event.trigger(myMarker, 'click');
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Última edición por mktalternativa; 06/01/2016 a las 11:16 |