Android谷歌地图中每个标记的不同信息窗口 [英] android different info window for each marker in google maps

查看:87
本文介绍了Android谷歌地图中每个标记的不同信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用for循环根据从数据库中检索到的位置在地图上做标记.

I am using a for loop to make markers on maps based on locations retrieved from database.

我有一个带有两个TextView的布局,我想用标记的名称和地址(从数据库中检索出来)填充.

I have a layout with two TextViews that i want to fill with the marker's name and address(retrieved from database).

我尝试使用googleMap.setInfoWindowAdapter(),但它所做的只是改变所有标记的布局(显然这不是我所需要的).

I tried using googleMap.setInfoWindowAdapter() but all it did was changing the layout for all markers altogether (which is obviously NOT what i need).

有没有办法让我独立更改每个标记的信息窗口?

So is there a way to allow me to change the info window of each marker independently?

推荐答案

实施onMarkerClickListener.获取标记对象,如下所示

Implement onMarkerClickListener. Get the marker object as follows

Marker marker = map.addMarker(new MarkerOptions().position(latLong)
            .title(string1).snippet(string2)));

单击标记后,您将获得覆盖标记的标记. 从中获取标题和摘录,如下所示.

You will get your marker in overridden method when you click on it. Get the title and snippet from it as follows.

@Override
public boolean onMarkerClick(Marker marker) {
    map.setInfoWindowAdapter(new MarkerAdapter(getActivity(), marker
            .getTitle(), marker.getSnippet()));
    return false;
}

祝你好运:)

这篇关于Android谷歌地图中每个标记的不同信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆