简体   繁体   English

android中谷歌地图中的自定义标记

[英]Custom marker in google maps in android

I want to add picture to marker in google maps.我想在谷歌地图的标记中添加图片。 I want to show after clicked on marker picture and on right side of that picture some text.我想在单击标记图片后显示该图片的右侧一些文本。 I create marker using this code:我使用以下代码创建标记:

Marker melbourne = map.addMarker(new MarkerOptions()
            .position(new LatLng(lblat,
                    lbLong))
            .title("Melbourne")
            .snippet("Population: 4,137,400")
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

but in that solution I have only title and snippet.但在那个解决方案中,我只有标题和片段。 How do marker on my way?我的路上怎么做标记?

You will have to inflate your own layout of the InfoWindow with an InfoWindowAdapter .你将不得不抬高自己的布局InfoWindowInfoWindowAdapter See the documentation here .请参阅此处的文档。

Here's a little example (I have this as an inner class in my map Activity ):这是一个小例子(我在我的地图Activity将此作为内部类):

class MyInfoWindowAdapter implements InfoWindowAdapter {

    private final View v;

    MyInfoWindowAdapter() {
        v = getLayoutInflater().inflate(R.layout.infowindow,
                null);
    }

    @Override
    public View getInfoContents(Marker marker) {

        ImageView icon = (ImageView) v.findViewById(R.id.icon); 
        // set some bitmap to the imageview         

        return v;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        // TODO Auto-generated method stub
        return null;
    }

}

And in your map Activity在你的地图Activity

gmap.setInfoWindowAdapter(new MyInfoWindowAdapter());

Good luck :)祝你好运 :)

If you want to customize your marker by using an image, you can add this image to the drawable folder, then:如果要使用图像自定义标记,可以将此图像添加到 drawable 文件夹,然后:

mMap.addMarker(new MarkerOptions()
.position(marq).icon(BitmapDescriptorFactory.fromResource((R.drawable.thenameofyourimage)))

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

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