我将PHP mysql用于我的谷歌地图。 将显示两个不同的标记(绿色表示ja(是),橙色表示nein(no))。但是当两个“东西”具有相同的纬度和长度时,只显示其中一个(例如:男人(ja)和女人(nein)住在同一个房子里) 我怎样才能得到两个标记?我不希望两个在同一个infowindow和没有集群。 首先是php:
$query = "SELECT ...";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-Type: text/xml; charset=utf-8");
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
parseToXML($row['kennelname'] .'</a>" ';
echo '<marker ';
if ($row['studlist'] == 'ja')
{echo 'studlist=" " ';} else {echo 'studlist="Daten nicht geprüft!" ';}
echo 'name="' . parseToXML($row['dogname']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['studlist'] . '" ';
echo ' />';
}
// End XML file
echo '</markers>';
和js:
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var customIcons = {
ja: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
nein: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_orange.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(51.162014, 10.450573),
zoom: 6,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("testfemale_de_xml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var id = markers[i].getAttribute("id");
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var studlist = markers[i].getAttribute("studlist");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html =
"<a href='/dog.php?id=" + id + "'>" + name + "</a>" +
"<br/><img src='/photo/" + id + "/" + id + ".jpg' height='70' width='' alt=''>" +
"<br />" +studlist
;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
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>
答案 0 :(得分:0)
当标记共享同一位置时,您将只看到一个。您可以使用标记的zIndex属性选择要显示的属性。例如:
marker.setZIndex(google.maps.Marker.MAX_ZINDEX + 1);