简体   繁体   English

Google Maps API v3,删除标记图标或更改为“空”?

[英]Google Maps API v3, Remove Marker icon or changing to “null”?

I'm writing a Python Flask application in which I'm using Google Maps.我正在编写一个使用 Google 地图的 Python Flask 应用程序。 I want to be able to add labels to a polyline that I've drawn which symbolizes a ship route.我希望能够将标签添加到我绘制的象征航线的折线。

The route is drawn using a set of coordinates and the polyline feature of the Maps API.路线是使用一组坐标和 Maps API 的折线功能绘制的。 I want to add time labels to the polyline and the easiest way seems to be to use Map Markers.我想向折线添加时间标签,最简单的方法似乎是使用地图标记。 However I don't want the large standard pins to show up, but would prefer a small icon/marker together with my text or even none at all.但是,我不希望出现大的标准图钉,但更喜欢将小图标/标记与我的文本一起显示,甚至根本不显示。 As far as I have gathered you can create "Circles" (which are modifiable) or "Markers" (which you only can change the icon of).据我所知,您可以创建“圆圈”(可修改)或“标记”(您只能更改其图标)。 I would prefer to go with "Circles", but those you apparently can't add text to..我更喜欢使用“圆圈”,但那些显然无法添加文本的..

How can I add text to my map and avoid the Google Maps Pins showing up?如何向我的地图添加文本并避免显示 Google 地图 Pin 图?

Currently I have an list of objects that contains latitude, longitude and date + time.目前我有一个包含纬度、经度和日期+时间的对象列表。 I'm iterating through it adding markers, but as I do I would like to keep out the marker icon or instead draw the circles if someone knows how to draw circles with added text?我正在迭代它添加标记,但正如我所做的那样,如果有人知道如何使用添加的文本绘制圆圈,我想保留标记图标或绘制圆圈?

for(i = 0; i < markerList.length; i++){
    var position = new google.maps.LatLng(markerList[i].lat, markerList[i].lng);
    var date = markerList[i].date;

    var marker = new google.maps.Marker({
        position: position,
        label: date,
        map: map,
        icon: "None" //Produces error: 404 (NOT FOUND)
    });
}

Being able to change the label size also is a very much appreciated function, but I have been unable to find any information about whether that is available.能够更改标签大小也是一个非常受欢迎的功能,但我一直无法找到有关该功能是否可用的任何信息。 Being able to change the color of the text would also be nice.能够改变文本的颜色也很好。

As no answers have been given yet and I've sort of found a solution to my problem I guess I will share for others out there with the same problem.由于还没有给出答案,我已经找到了解决我的问题的方法,我想我会与其他有同样问题的人分享。 At least until someone comes up with a better solution:至少在有人想出更好的解决方案之前:

I ended up using a predefined symbol and scaling it down to 0 in size as follows:我最终使用了一个预定义的符号并将其缩小到 0,如下所示:

for(i = 0; i < markerList.length; i++){
    var position = new google.maps.LatLng(markerList[i].lat, markerList[i].lng);
    var date = markerList[i].date;

    var marker = new google.maps.Marker({
        position: position,
        label: date,
        map: map,
        icon: {
            path: google.maps.SymbolPath.CIRCLE,
            scale: 0
        }
    });
}

Sadly I haven't found a way to mess with the label yet.可悲的是,我还没有找到弄乱标签的方法。

try markerWithlabel and you can change the icon of the marker whit a svg or png plus the label too尝试markerWithlabel ,您也可以更改带有svg或png的标记图标以及标签

like this jsfiddel .就像这个jsfiddel .

@Zeliax You can add visible: false to not have marker icon show on your google map. @Zeliax 您可以添加visible: false以在您的谷歌地图上不显示标记图标。 icon prop looks for a path that you want specify for your marker to look as. icon prop 查找您要为标记指定的路径。 It is basically a url for your display image.它基本上是您的显示图像的网址。

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

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