简体   繁体   English

谷歌地图api添加自定义图标

[英]google maps api adding custom icon

Bit of a strange one - I created a google maps area for a contact page on a site I'm working on. 有点奇怪 - 我为我正在工作的网站上的联系页面创建了一个谷歌地图区域。 All worked fine voila etc. I went back to change some more stuff on the page today and the icon has completely disappeared. 所有工作都很好瞧等我今天回去改变页面上的更多东西,图标已经完全消失了。 The map still generates and displays fine - only the icon is missing. 地图仍然生成并显示正常 - 只有图标丢失。 My img path is still correct and nothing else has changed. 我的img路径仍然正确,没有其他任何改变。 I seemed to vaguely remember this happening during original build but it may have fixed itsself. 我似乎依旧记得在原始版本中发生了这种情况,但它可能已经修复了自己。 Has anyone else came across similar things? 还有其他人遇到类似的事情吗?

My JS for the map is here - When I deliberately change to a non existent or non valid var the map wont generate so I;m not entirely certain it is an error with this code. 地图的我的JS在这里 - 当我故意改为不存在或无效的var时,地图不会生成所以我;我不完全确定它是这个代码的错误。

any help would be massively appreciated. 任何帮助都会受到大力赞赏。 Thanks, 谢谢,

    <script type="text/javascript">
    function initialize() {
        var latlng = new google.maps.LatLng(51.865151,-2.234739);
        var settings = {
            zoom: 16,
            center: latlng,
            mapTypeControl: true,
            scrollwheel: false,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: true,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
    var companyLogo = new google.maps.MarkerImage('img/gmap-icon.png',
    new google.maps.Size(100,50),
    new google.maps.Point(0,0),
    new google.maps.Point(50,50)
);
      var companyPos = new google.maps.LatLng(51.865151,-2.234739);
      var companyMarker = new google.maps.Marker({
    position: companyPos,
    map: map,
    icon: companyLogo,
    title:"10 Yetis HQ"
});

    }

</script>

I faced a similar situation like this , try to change icon path directly to the physical path 我遇到了类似这样的情况,尝试直接将图标路径更改为物理路径

Icon: "images/greymarker.png"

or else you can even use 或者你甚至可以使用

companyMarker.setIcon("images/bluedot.png");

Hope this helps :D 希望这会有所帮助:D

I think you have a problem with browser cache. 我认为你的浏览器缓存有问题。 Clear your cache every time to make a change of you will be seeing a mixed version of changes. 每次清除缓存以进行更改时,您将看到混合版本的更改。

Also, because you are using javascript, most paths are not relative. 此外,因为您使用的是javascript,所以大多数路径都不是相对的。 Try using absolute urls. 尝试使用绝对网址。 For example: 例如:

var companyLogo = new google.maps.MarkerImage('/img/gmap-icon.png', ...);

thank you both for the answers :) unfortunately it was something more simple. 谢谢你们的答案:)不幸的是,它更简单。 My JS was executing before my dvi had been rendered in the DOM - I noticed a few errors in the JS console on Chrome and sorted it. 我的JS在我的dvi在DOM中呈现之前正在执行 - 我注意到Chrome上的JS控制台中有一些错误并对其进行了排序。 thank you both!! 谢谢你俩!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM