简体   繁体   English

如何在谷歌地图折线的中心设置折线标记?

[英]How to set polyline marker on the center of the polyline of google map?

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.如果我通过使用路径(路径:google.maps.SymbolPath.FORWARD_CLOSED_ARROW)使用 Google API 提供的图标,它会显示在线的中心。

Please see the below image:请看下图: 在此处输入图片说明

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.您将需要修改图标的anchor 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.您的示例分支中,我添加了anchor: new google.maps.Point(23, 0) ,在 Google Maps 文档中的Complex 图标下有一些额外属性的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM