简体   繁体   English

如何使用我的功能(谷歌地图)在我的地图中显示 1 张以上的图像

[英]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.

相关问题 为什么我的网站上没有超过1-2个Google地图? - Why can I not have more than 1-2 google maps on my website? 在我的网站上显示谷歌地图,就像它在谷歌地图中显示的一样 - show google map on my site just as it show in google maps 单击超链接时,如何使用Google Maps API v3缩放地图? - How do I zoom my map using Google Maps API v3 when I click a hyperlink? 如何在自定义地图的名称中添加超链接? 谷歌地图API v3 - How i can add a hyperlink in the name of my custom map? google maps api v3 如何使用新的 google.maps 在 vue2-google-map 上使用标记的 @drag function? - How can I use @drag function of marker on vue2-google-map using new google.maps? 仅当图像列表中有多个图像时,才显示“删除”链接 - Show my link “Delete” only if I have more than one image in my image list Google地图“center_changed”不止一次触发我的功能 - Google Maps “center_changed” is firing my function more than once 如何使用Google Static Maps API获取指向地图图像的静态URL? - How can I get a static URL to a map image using the Google Static Maps API? 我怎样才能在谷歌地图上显示我的数据库地址而没有纬度和经度? - how i can i show my database address on google map with out lat and long? 如何将我的Google地图变成一张图片? 不能用鼠标移动吗? - How do I turn my Google Maps into just an image? And not movable using the mouse?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM