我知道有很多关于这个问题的话题,但是我已经尝试了所有方法,但仍无法解决我的问题。
我试图根据他们的位置在谷歌地图上显示我的成员。问题在于,尽管注册了34个成员,但只显示了15-22个(每次刷新时随机选择)标记。
地址已正确地进行地理编码,因为如果我进入成员页面,其标记会显示在地图上。我认为这是数据加载的一些问题,但我不知道如何解决它。
我在Joomla网站上使用swmap插件。下面列出了JQuery代码。
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&language='.$locale.'"></script>
<script type="text/javascript">
window.addEvent("load",function(){initialize();});
var beaches = '.json_encode($res).';
function initialize() {
var myLatlng = new google.maps.LatLng('.$lat_center.', '.$long_center.');
var myOptions = {
zoom: 10,
center: myLatlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.'.$cattype.'
}
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
google.maps.event.addListener(map, \'click\', function() {
infowindow.close();
});
setMarkers(map, beaches);
}
var icons = new Array();
icons["red"] = new google.maps.MarkerImage("'. JURI::root() .'plugins/k2/swmap/'.$color.'/landmark.png",
new google.maps.Size(32, 32),
new google.maps.Point(0,0),
new google.maps.Point(0, 32));
function getMarkerImage(iconColor) {
if ((typeof(iconColor)=="undefined") || (iconColor==null)) {
iconColor = "red";
}
if (!icons[iconColor]) {
icons[iconColor] = new google.maps.MarkerImage("'. JURI::root() .'plugins/k2/swmap/'.$color.'/"+ iconColor +"",
new google.maps.Size(32, 32),
new google.maps.Point(0,0),
new google.maps.Point(0, 32));
}
return icons[iconColor];
}
var iconImage = new google.maps.MarkerImage(\''. JURI::root() .'plugins/k2/swmap/'.$color.'/landmark.png\',
new google.maps.Size(32, 32),
new google.maps.Point(0,0),
new google.maps.Point(0, 32));
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
function createMarker(map, latlng, label,link, html, color) {
var contentString = \'<b>\'+link+\'</b><br>\'+html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: getMarkerImage(color),
title: label,
zIndex: Math.round(latlng.lat()*-100000)<<5
});
google.maps.event.addListener(marker, \'click\', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
}
function setMarkers(map, locations) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = createMarker(map,myLatLng,beach[0],beach[5],beach[4],beach[3]);
bounds.extend(myLatLng);
map.fitBounds(bounds);
}
}
答案 0 :(得分:1)
请参阅this article on Geocoding Strategies from the documentation
最佳做法是存储不会更改的位置坐标,并使用它们来显示标记。使用客户端地理编码器仅对用户在输入时输入的信息进行地理编码。