在我的地图中,我有一些标记列表,现在我需要实现输出,如下所示
即。索引号的标记。
我搜索了谷歌,但没有得到任何解决方案,请帮我理解实现这一点。
答案 0 :(得分:3)
我已经做了一个非常灵活和有趣的黑客来实现你想要的任何标记。
我的工作是,
创建XML布局文件,并按照您希望标记显示的方式进行设计。例如,在你的情况下,它将是一个带有TextView的绿色标记图像。
根据要求设置TextViews的值。
将布局文件转换为图像并获取BitmapDescriptor对象。
使用刚刚创建的图片创建自定义标记。
此类视图对Info Window的好处是您可以同时打开多个标记的窗口。与在InfoWindow中一样,您只能一次打开一个标记。
答案 1 :(得分:2)
对于自定义标记:
custom image
和draw
以及index number
image
Marker Window
:
您可以创建包含xml
和ImageView
的自定义TextViews
文件:
类似于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>
初始化Markers
后,请致电setInfoWindowAdapter
并充气your custom view
。类似的东西:
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;
}
});
}