【问题标题】:Map marker title does not show full text on Google map V2地图标记标题在 Google 地图 V2 上不显示全文
【发布时间】:2014-07-12 09:17:08
【问题描述】:

我在地图上有多个标记及其信息。通过点击特定标记,它会显示信息。 下面是添加多个标记的代码:

for (int i = 0; i < list.size(); i++) {
    MarkerOptions markerOptions = new MarkerOptions();
    HashMap<String, String> hmPlace = list.get(i);
    double lat = Double.parseDouble(hmPlace.get("lat"));
    double lng = Double.parseDouble(hmPlace.get("lng"));
    String name = hmPlace.get("place_name");
    String vicinity = hmPlace.get("vicinity");
    LatLng latLng = new LatLng(lat, lng);
    markerOptions.position(latLng);
    markerOptions.title(name + ":" + vicinity);
    googleMap.addMarker(markerOptions);
}

我的输出如下所示:

当我点击标记时,它不会显示全文。取而代之的是,它向我显示了一些文本,然后显示了一些点。

Google Map V2 中有什么方法可以显示全文吗?我已经使用了“MarkerOptions”类的title() 方法。

【问题讨论】:

  • 如果你使用了Default Marker,那就没有办法了。但是你可以使用Custom Marker Window
  • Lawrence,没有任何方法可以解决这个问题,它默认的谷歌地图的东西,但你可以在使用自定义标记后做到这一点。
  • @pratik 你能给我自定义标记的链接吗?
  • @Lawrence 是的,为什么不呢
  • 不要使用Marker.title(String),它会在文本溢出时省略,而是使用Marker.snippet(String)

标签: android google-maps google-maps-api-2


【解决方案1】:

感谢您的帮助。但我解决了我的问题。

只需创建一个扩展 InfoWindowAdapter 的类。

class MyInfoWindowAdapter implements InfoWindowAdapter {

    private final View myContentsView;
    private String name, vicinity;

    public MyInfoWindowAdapter(String name, String vicinity) {
        myContentsView = getLayoutInflater().inflate(
                R.layout.custom_info_contents, null);
        this.name = name;
        this.vicinity = vicinity;
    }

    @Override
    public View getInfoContents(Marker marker) {

        TextView tvTitle = ((TextView) myContentsView
                .findViewById(R.id.title));
        tvTitle.setText(name);
        TextView tvSnippet = ((TextView) myContentsView
                .findViewById(R.id.snippet));
        tvSnippet.setText(vicinity);

        return myContentsView;
    }

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

}

并使用 GoogleMap 的 setInfoWindowAdapter() 方法。

googleMap.setInfoWindowAdapter(new MyInfoWindowAdapter(name,
                    vicinity));

【讨论】:

  • @pratik 是的,工作完美。只需添加“markerOptions.title(name);markerOptions.sn-p(vicinity);”
  • 嘿,那很好,我刚刚准备好你的代码发送给你,但如果你完成了它就很好
【解决方案2】:

试试下面的代码

MarkerOptions options = new MarkerOptions();
    options.position(origin); 
    options.title("Current Location");
    options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
    mMap.addMarker(options);

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    相关资源
    最近更新 更多