Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Google Map v2自定义标记中写入文本-Android_Android_Google Maps Markers - Fatal编程技术网

在Google Map v2自定义标记中写入文本-Android

在Google Map v2自定义标记中写入文本-Android,android,google-maps-markers,Android,Google Maps Markers,在我的地图中,我有一些标记列表,现在我需要实现如下输出 i、 e.带有索引号的标记 我在谷歌上搜索过,但没有找到任何解决方案,请帮我想一个办法来实现这一点。对于自定义标记: 您可以创建一个自定义图像和绘图索引编号 那个图像 请检查此示例以了解更多信息 对于标记窗口: 您可以创建一个自定义的xml文件,其中包含ImageView和textview: 类似于customMapView.xml: <RelativeLayout xmlns:android="http://schemas.an

在我的地图中,我有一些标记列表,现在我需要实现如下输出

i、 e.带有索引号的标记

我在谷歌上搜索过,但没有找到任何解决方案,请帮我想一个办法来实现这一点。

对于自定义标记:

  • 您可以创建一个
    自定义图像
    绘图
    索引编号 那个
    图像
  • 请检查此示例以了解更多信息
对于标记窗口:

您可以创建一个自定义的
xml
文件,其中包含
ImageView
textview

类似于
customMapView.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/white_full"
    android:layout_width="match_parent"
    android:padding="@dimen/padding_micro"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/img"
        android:layout_gravity="left"
        android:src="@drawable/ic_launcher"
        android:textColor="@color/black_full"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:gravity="right"
        android:id="@+id/name"
        android:text="test"
        android:textColor="@color/black_full"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

      <!-- Other TextViews or Whatever you want-->

</RelativeLayout>
用谷歌地图标记做任何你想做的事 我已经做了一个非常灵活和有趣的黑客实现任何类型的标记你想要的

我所做的是

  • 创建一个XML布局文件,并按照您希望的标记显示方式进行设计。例如,在您的例子中,它将是一个绿色标记图像,上面有一个文本视图

  • 根据需要设置文本视图的值

  • 将布局文件转换为图像并获取BitmapDescriptor对象

  • 使用刚创建的图像创建自定义标记

  • “查看信息”窗口的好处是,您可以同时打开多个标记的窗口。在InfoWindow中,一次只能打开一个标记

    代码示例

    感谢您提供custommarker链接。这提供了一个线索,以获得解决方案:)请问你是如何做的图标与数字?Thanks@ItuokeAjanlekoko首先将标记转换为位图,然后使用绘画和画布在标记上书写数字。
        private void customizeMarkerInfoWindow(){
            //Setting custom info window
            mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
                //Use default infoWindow frame
                @Override
                public View getInfoWindow(Marker marker) {
                    return null;
                }
    
                @Override
                public View getInfoContents(Marker marker) {
                    // Getting view from the layout file
                    View view = mActivity.getLayoutInflater().inflate(R.layout.customMapView, null);
                    // Getting the position from the marker
                    LatLng latLng = marker.getPosition();
                    //UI elements
                    ImageView img = (TextView) view.findViewById(R.id.img);
                    TextView coord = (TextView) view.findViewById(R.id.name);
                    mukAdTv.setText(mukAd);
                    //You set the image here depending on how you want to set it, if you are downloading from internet you can use PICASSO for it and set it to img
                    //With picasso
                    Picasso.with(mActivity).load(YOUR_IMAGE_URL).into(img);
                    //From drawables
                    //img.setBackground(yourDrawable);
                    name.setText(latLng.latitude + ", " + latLng.longitude);
    
                    return view;
                }
            });
        }