I am getting stuck when trying to set google map's polyline icon on the center of a line.
I am using a custom car icon which is not getting set properly on the polyline that I am drawing on the map. Please see the screenshot:
If I use the icon provided by the Google API by using path (path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW) it shows on the center of the line.
How can we set the car icon on the middle of the line? Please check the sample code here.
For the car icon I am using the below code, is anything needed to be modified here?
var iconsetngs = {
path: 'M25.395,0H17.636c-3.117,0-5.643,3.467-5.643,6.584v34.804c0,3.116,2.526,5.644,5.643,5.644h11.759' +
'c3.116,0,5.644-2.527,5.644-5.644V6.584C35.037,3.467,32.511,0,29.395,0z M34.05,14.188v11.665l-2.729,0.351v-4.806L34.05,14.188z' +
'M32.618,10.773c-1.016,3.9-2.219,8.51-2.219,8.51H16.631l-2.222-8.51C14.41,10.773,23.293,7.755,32.618,10.773z M15.741,21.713' +
'v4.492l-2.73-0.349V14.502L15.741,21.713z M13.011,37.938V27.579l2.73,0.343v8.196L13.011,37.938z M14.568,40.882l2.218-3.336' +
'h13.771l2.219,3.336H14.568z M31.321,35.805v-7.872l2.729-0.355v10.048L31.321,35.805z',
fillColor: 'blue',
fillOpacity: 1,
scale: 0.4,
strokeColor: 'gray',
strokeWeight: 0.4,
offset: '50%'
};
var polyOptions = new google.maps.Polyline({
path: path,
strokeColor: '#0c0bbb',
strokeWeight: 1.5,
map: this.map,
icons: [{
icon: iconsetngs,
repeat: '70px',
}]
});
polyOptions.setMap(this.map);
You will need to modify the anchor
point of the icon. In the fork of your example I have added anchor: new google.maps.Point(23, 0)
, there are some details of the extra poperties available under Complex icons in the Google Maps documentation.