2010-11-30 95 views
9

我有一张使用DirectionsRender绘制的路线,但我找不到如何用我自己的替换通用Google标记。如何在谷歌地图v3 API中更改开始和结束标记图像

我知道并在正常的Google地图情况下使用它,但发现使用指示标记开始和结束时很难做到这一点。

感谢您的任何意见,指针或温和的嘲讽,如果这是一个愚蠢的问题:d

迈克尔

回答

3

这就是你需要如何处理它

声明你的所有的图像图标,如图下面

var movingIcon = new google.maps.MarkerImage('/img/icon_moving.jpg'); 
var startIcon = new google.maps.MarkerImage('/img/icon_start.png'); 

然后在创建标记,使用IC上选项来特定图像设置为标记

marker = new google.maps.Marker({ 
      position: point, 
      map: map, 
      icon: movingIcon 
      }); 
+2

他问的是如何更改标记的方向呈现这只是回答如何更改标记图标。 – 2012-02-09 13:51:50

6

DirectionRender接受一个选项称为markerOptions。从API文档引用:

DirectionsRenderer呈现的所有标记都将使用这些选项。

所以,如果你想设置标记使用MarkerImage(如philar已指示)。

您的其他选择是通过suppressMarkers: trueDirectionRender的选项,然后只需使用自己的标记。

2

首先,你需要添加这对您的DirectionsRenderer

directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true}); 
//to hide the default icons 

再经过选择等等

map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); 
//you set your custom image 
var image = new google.maps.MarkerImage('images/image.png', 
        new google.maps.Size(129, 42), 
        new google.maps.Point(0,0), 
        new google.maps.Point(18, 42) 
       ); 

//you set your icon for each of the direction points Origin 
       var marker1 = new google.maps.Marker({ 
        position: new google.maps.LatLng(19.432651,-99.133201), 
        map: map, 
        icon: image 
       }); 
//you set your icon for each of the direction points Destination, 
       var marker2 = new google.maps.Marker({ 
        position: new google.maps.LatLng(45.508648,-73.55399), 
        map: map, 
        icon: image 
       }); 

,你也可以为始发地和目的地添加不同的图标。只需使用var图像, 它适合我!

相关问题