简体   繁体   English

如何获得谷歌地图标记的图标?

[英]How to get Icon of Google Maps marker?

With marker.getTitle() you get the title of a marker, but how can I ask for the icon?使用marker.getTitle() 可以获得一个标记的标题,但我怎么能要求图标呢? I want to ask if the icon of a marker is set to certain drawable and if so do something.我想问一下标记的图标是否设置为某些可绘制的,如果是,请执行某些操作。

Well you can create marker with new MarkerOptions() Like this:好吧,您可以使用 new MarkerOptions() 创建标记,如下所示:

map.addMarker(new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.house_flag))
            .anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
            .position(new LatLng(41.889, -87.622)));

So you can simply store this data in some linked list or hash map所以你可以简单地将这些数据存储在某个链表或哈希映射中

Without context on why you need the Icon, it is really hard to understand why you want it.如果没有关于为什么需要 Icon 的上下文,真的很难理解你为什么想要它。

If you just want to move the marker or change the rotation you can do that by saving a variable for the Marker.如果您只想移动标记或更改旋转,您可以通过为标记保存变量来实现。

Marker allows .setPosition(LatLng) and .setRotation(Float).标记允许 .setPosition(LatLng) 和 .setRotation(Float)。

Hope this helps someone since this is an old question希望这对某人有所帮助,因为这是一个老问题

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

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