gpt4 book ai didi

javascript - Google Maps V3 在确切位置上重叠标记

转载 作者:可可西里 更新时间:2023-11-01 01:52:44 28 4
gpt4 key购买 nike

我遇到标记重叠的问题,请不要投票,因为我没有受过 javascript 的高等教育,我也看过 stackoverflow 上提供的不同答案,但无法使用它们找到解决方案,所以请帮忙!该代码根据我给出的静态点获取经纬度的 php 我只想在同一标记中列出所有信息,而不是让它与标记重叠任何帮助将不胜感激这里是代码:

  <head>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<META HTTP-EQUIV="refresh" >
<title>Operations</title>

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=APIKEY&sensor=false"></script>
<script src="oms.min.js"></script>
<script type="text/javascript">
//<![CDATA[

var customIcons = {

restaurant: { icon: 'mm_20_blue.png' },

bar: { icon: 'mm_20_blue.png' }

};

function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(32.298342, -64.791098),
zoom: 17,
mapTypeId: google.maps.MapTypeId.SATELLITE
});
var infoWindow = new google.maps.InfoWindow;

// Change this depending on the name of your PHP file
downloadUrl("genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var id = markers[i].getAttribute("permitnumber");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address + "<br/>" + '<a href="http://server/editform.php?find=' + id + '" >More Info</a> <br/> <form action="del.php" method="post" enctype="multipart/form-data"> <input type="checkbox" name="checkbox" id="checkbox" value="' + id +'"> <input name="delete" type="submit" id="delete" value="Delete"> ' ;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow,
animation: google.maps.Animation.BOUNCE

});

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>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js" type="text/javascript"></script>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24568877-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google- analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

</head>

<body onload="load()" bgcolor="#A8F748" >

<div id="map" style="margin:auto; width: 90%; height: 470px"></div>






</body>

最佳答案

如果您不希望标记重叠,您可能需要使用 google-maps-utility-library-v3 .它有一个称为 Marker Clusterer 的功能,它基本上允许您将附近的标记放入一个单一的标记中。可以对其进行配置,以便一旦用户放大到足够远,这些标记就会重新显示为单独的实体。 Here's a demo .

关于javascript - Google Maps V3 在确切位置上重叠标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19821198/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com