简体   繁体   English

Javascript Google Maps API图标

[英]Javascript Google Maps API icon

For the last week and a half I have been tinkering with a script for my website. 在过去的一个半星期里,我一直在为自己的网站修改脚本。 I slightly altered it but have hit a skills wall. 我对其进行了些微修改,但遇到了一些技术障碍。 It works perfectly at the moment but I would love to add a custom marker icon. 目前,它可以完美运行,但我想添加一个自定义标记图标。 I have tried loads using lots of example code but am getting knowhere. 我已经尝试使用许多示例代码进行加载,但是在这里已经知道了。 I have saved an image on my google drive at 我已将图片保存在Google驱动器上,网址为

" https://drive.google.com/open?id=0B8DJ6pJV3E9FWmFiUlFTWGl5RjA " https://drive.google.com/open?id=0B8DJ6pJV3E9FWmFiUlFTWGl5RjA

Please can anyone show me how to incorporate it into the code below which I know works. 请任何人告诉我如何将其合并到下面我知道有效的代码中。

 <div id="map" style="height: 500px; width: 500px; float:left; border:1px solid black; "></div> <div id="sidebar" style="height: 500px; width: 300px; float:left; margin: 40px; vertical-align: top; line-height: 30px; margin-top: -10px; "></div> <script src="https://maps.googleapis.com/maps/api/js"></script> <script> var markers = []; var map; var infoWin; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: {lat: -34.397, lng: 150.644}, zoom: 8 }); infoWin = new google.maps.InfoWindow(); createMarker(new google.maps.LatLng( -33.8, 151.0), "Place 1", "Address 1", map); createMarker(new google.maps.LatLng( -33.8, 151.1), "Place 2", "Address 2", map); } google.maps.event.addDomListener(window, 'load', initMap); function createMarker(latlng, name, html, map) { var marker = new google.maps.Marker({ position: latlng, map: map }); google.maps.event.addListener(marker, 'click', function(evt) { infoWin.setContent("<h3>"+name+"</h3>"+html); infoWin.open(map,marker); }); var sideaddress = [name] markers.push(marker); document.getElementById('sidebar').innerHTML += '<a href="javascript: google.maps.event.trigger(markers['+(markers.length-1)+'],\\'click\\');">'+sideaddress+'</a><br>'; } </script> 

You ran into same problem as I did once, you just need to host your image image locally(localhost) or anywhere on web and then use it's url to set marker url path. 您遇到了与我一次相同的问题,只需要在本地(本地主机)或网络上的任何地方托管图像,然后使用其url设置标记url路径。

If you are using chrome, use app 'Web Server' from App Store to host your project folder that includes the image as well. 如果您使用的是chrome,请使用App Store中的应用程序“ Web Server”来托管包含图像的项目文件夹。

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

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