我怎样才能改变谷歌的方向模式api的源和目的地的标记



我已经渲染了一个谷歌地图,用于绘制源和目的地之间的路由,在IOS应用程序的react native中使用这个api。

`https://www.google.com/maps/embed/v1/directions
?key=YOUR_API_KEY
&origin=Oslo+Norway
&destination=Telemark+Norway
&avoid=tolls|highways`

我想改变我的开始和结束的自定义标记,只需要在标记上一个字母。

请帮我一下。谢谢你。

尝试在DirectionsRenderer上使用suppressMarkers选项来阻止路由上的标记被显示。您需要将DirectionsDisplay的值设置为TRUE

下面是如何使用suppressMarkers的示例代码片段:

// Map and directions objects
var map = new google.maps.Map( element, options );
var service = new google.maps.DirectionsService();
var directions = new google.maps.DirectionsRenderer({suppressMarkers: true});
// Start/Finish icons
var icons = {
start: new google.maps.MarkerImage(
// URL
'start.png',
// (width,height)
new google.maps.Size( 44, 32 ),
// The origin point (x,y)
new google.maps.Point( 0, 0 ),
// The anchor point (x,y)
new google.maps.Point( 22, 32 )
),
end: new google.maps.MarkerImage(
// URL
'end.png',
// (width,height)
new google.maps.Size( 44, 32 ),
// The origin point (x,y)
new google.maps.Point( 0, 0 ),
// The anchor point (x,y)
new google.maps.Point( 22, 32 )
)
};
service.route( { origin: origin, destination: destination }, function( response, status ) {
if ( status == google.maps.DirectionsStatus.OK ) {
display.setDirections( response );
var leg = response.routes[ 0 ].legs[ 0 ];
makeMarker( leg.start_location, icons.start, "title" );
makeMarker( leg.end_location, icons.end, 'title' );
}
});
function makeMarker( position, icon, title ) {
new google.maps.Marker({
position: position,
map: map,
icon: icon,
title: title
});
}

最新更新