[英]How can i show more than 1 image in my map using my function (google maps)
This is my first question here so please be cool with me.这是我在这里的第一个问题,所以请对我保持冷静。 I'm trying to use add more than only one image to my markers using this code.我正在尝试使用此代码将多个图像添加到我的标记中。 Everything is alright but when I display the info all my markers are the same image instead of the one they have on my BD.一切都很好,但是当我显示信息时,我的所有标记都是相同的图像,而不是它们在我的 BD 上的图像。 I guess it's because my loc.marker but I really do not get it.我想这是因为我的 loc.marker 但我真的不明白。 If someone can give me a hand i will be grateful如果有人可以帮我一把,我将不胜感激
Here is my function:这是我的功能:
function setMarkers(locObj) {
<?php for ($i=0; $i<count($plak); $i++) { ?>
$.each(locObj, function(key, loc) {
if (!locations[key] && loc.lat !== undefined && loc.lng !== undefined) {
loc.marker = new google.maps.Marker({
position: new google.maps.LatLng(loc.lat, loc.lng),
map: map,
icon: 'profile/img/<?php echo $carr[$i] ?>.png'
});
google.maps.event.addListener(loc.marker, 'click', (function(key) {
return function() {
infowindow.setContent(locations[key].info);
infowindow.open(map, locations[key].marker);
}
})(key));
locations[key] = loc;
} else if (locations[key] && loc.remove) {
if (locations[key].marker) {
locations[key].marker.setMap(null);
}
delete locations[key];
} else if (locations[key]) {
$.extend(locations[key], loc);
if (loc.lat !== undefined && loc.lng !== undefined) {
locations[key].marker.setPosition(new google.maps.LatLng(loc.lat, loc.lng));
}
}
});
<?php } ?>
}
I add that for
because the $plak
brings to me a number of registers that will be display and $carr[]
is an array that brings to me all images name in order to place them in the markers and in the map.我添加它for
因为$plak
为我带来了许多将被显示的寄存器,而$carr[]
是一个数组,它为我带来了所有图像名称,以便将它们放置在标记和地图中。
UPDATE I did it, just added the images into an ajax file so i just call icon:icon.images
, delete the for
and it shows me what I want.更新我做到了,只是将图像添加到 ajax 文件中,所以我只需调用icon:icon.images
,删除for
并显示我想要的内容。 Thanks for everything感谢一切
your problem is that generate n times generate same code in PHP, Have you ever looked your page source code?你的问题是在PHP中生成n次生成相同的代码,你有没有看过你的页面源代码? When you looked it then understand what I am saying hence you see same images on marker, I try to present your function code below当你看到它然后明白我在说什么,因此你在标记上看到相同的图像,我尝试在下面展示你的功能代码
$plak has these values 1-A, 2-B, 3-C
function setMarkers(locObj) {
$.each(locObj, function(key, loc) {
if (!locations[key] && loc.lat !== undefined && loc.lng !== undefined) {
loc.marker = new google.maps.Marker({
position: new google.maps.LatLng(loc.lat, loc.lng),
map: map,
icon: 'profile/img/A.png'
});
......
$.each(locObj, function(key, loc) {
if (!locations[key] && loc.lat !== undefined && loc.lng !== undefined) {
loc.marker = new google.maps.Marker({
position: new google.maps.LatLng(loc.lat, loc.lng),
map: map,
icon: 'profile/img/B.png'
});
......
$.each(locObj, function(key, loc) {
if (!locations[key] && loc.lat !== undefined && loc.lng !== undefined) {
loc.marker = new google.maps.Marker({
position: new google.maps.LatLng(loc.lat, loc.lng),
map: map,
icon: 'profile/img/C.png'
});
......
}
then C marker images override other marker images in same place.然后 C 标记图像覆盖同一位置的其他标记图像。 Enjoy享受
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.