javascript - 添加自定义图标到谷歌地图

标签 javascript google-maps

我需要有人向某些 Google map javascript 添加自定义图标。

以下代码供您引用:

function populateMap() {
 var map = new GMap2(document.getElementById("map"));
 map.setCenter(new GLatLng(55.915832522285235, -3.5911989212036133), 10);
 map.setUIToDefault();



 var points = new Array(5);

  points[1] = [55.992602,-3.92968,'<div class="infoContainer"><h2><a href="#">Mayfield Drive, Longcroft, Bonnybridge<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[2] = [55.9471382,-3.9729174,'<div class="infoContainer"><h2><a href="#">Oakwood Cumbernauld<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[3] = [55.933873,-3.12406,'<div class="infoContainer"><h2><a href="#">Wauchope Square, Edinburgh<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[4] = [55.843728,-3.95258,'<div class="infoContainer"><h2><a href="#">Gibb Street, Chapelhall<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];



  points[5] = [55.854559,-4.000543,'<div class="infoContainer"><h2><a href="#">Paddock Street, Sikeside<\/a><\/h2><p class="address">{locations_address}<\/p><\/div>'];




 for(var i=1; i < points.length; i++) {
  var point = new GLatLng(points[i][0],points[i][1]);
  var windowInfo = points[i][2];
  var marker = createMarker(point,windowInfo);
  map.addOverlay(marker);
 }
}

    function createMarker(point, overlayText) {
 var marker = new GMarker(point);
 GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(overlayText);});
 return marker;
}

    function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 } else {
  window.onload = function() {
   if (oldonload) {
    oldonload();
   }
   func();
  }
 }
}

addLoadEvent(populateMap);

最佳答案

谷歌地图 API 页面似乎都不起作用,但这可能会帮助任何遇到类似问题的机构

// Create our "tiny" marker icon
var centreicon = new GIcon();
centreicon.constructor
centreicon.image = "http://maps.google.com/mapfiles/kml/pal3/icon31.png ";
centreicon.shadow = "http://maps.google.com/mapfiles/kml/pal3/icon31s.png ";
centreicon.iconSize = new GSize(12, 20);
centreicon.shadowSize = new GSize(22, 20);
centreicon.iconAnchor = new GPoint(6, 20);
centreicon.infoWindowAnchor = new GPoint(5, 1);

......你的代码来创建 map

           var marker = new GMarker(point, centreicon);

           map.addOverlay(marker);

关于javascript - 添加自定义图标到谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1734078/

相关文章:

javascript - 在谷歌地图中使用数组居中并打开 InfoWindow

javascript - 如何在使用 javascript 加载文档时执行 css3 转换?

javascript - 创建一个时间间隔,使函数在 JavaScript 中随机运行

javascript - typescript :使用 map 时数组数组失败

google-maps - 谷歌地图 API 地理编码不如手动搜索精确,为什么?

javascript - 使用标记将自定义 Google map 嵌入到网站

javascript - 如何在 <div> 中动态更改所有段落文本的颜色和大小?

php - 从 PHP 调用 JavaScript 函数的问题

javascript - 如何撤消谷歌地图绘图中最后添加的线

django - Django中获取特定半径内的所有点