[ACCEPTED]-Change individual markers in google maps directions api V3-google-maps-api-3
Accepted answer
For those that need an example like I did, here's 6 a basic one:
// 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
});
}
The response from a route request 5 returns a leg(s) depending on the number 4 of stops on your route. I am only doing 3 a A to B route, so just take the first leg, and 2 get the position of where the markers need 1 to go, and create markers for those spots.
Do as they say on that page you linked to:
- Set the suppressMarkers option to true to prevent the default start and end markers from showing
- Create the images for the two new markers
- Create the markers with the position set to the start and end positions, and the icon set to the ones you created
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.