Android 自定义标记图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10077494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:24:45  来源:igfitidea点击:

Android Custom marker icon

androidmarker

提问by Jamel Naghmouchi

I'm working on application with Google maps so i want to define a custom marker for each custom place, For example (gas station- Hotel- Hospital.. ) ! i have a overlays class with the latitude and longitude of many places and i want just how to give a custom icon!

我正在使用谷歌地图应用程序,所以我想为每个自定义地点定义一个自定义标记,例如(加油站-酒店-医院..)!我有一个包含许多地方的经纬度的叠加类,我只想如何提供自定义图标!

回答by Janusz

With the new Maps Api Setting the Icon for a Markeris done with the following Code:

使用新的 Maps Api 设置标记图标是使用以下代码完成的:

MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_location));

The icon can not be changed after a Marker was created. To change an icon remove the marker and readd it with a new image.

创建标记后无法更改图标。要更改图标,请移除标记并使用新图像读取它。

回答by rajankz

with the APi v2, you can do (markerObject).setIcon(BitmapDescriptor)to change/set the marker image.

使用 API v2,您可以(markerObject).setIcon(BitmapDescriptor)更改/设置标记图像。

回答by Md. Nazmul Islam

To change the color of the map icon:

要更改地图图标的颜色:

mMap.addMarker(new MarkerOptions().position(baitulMosque).title("Baitul Mosque").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));

回答by ravuya

OverlayItem.setMarkerseems like the method you're looking for.

OverlayItem.setMarker似乎是您正在寻找的方法。

Note that there is (or used to be) a gotchayou need to be aware of; you first need to use Drawable.setBoundsto set the visible boundaries of the drawable before it can be rendered properly. Some fiddling might be needed to get it to centre; see this answer.

需要注意的是有(或曾经是)一个疑难杂症,你需要知道的; 您首先需要使用Drawable.setBounds来设置可绘制对象的可见边界,然后才能正确呈现。可能需要一些摆弄才能让它居中;看到这个答案