地图标记标题不会在Google地图V2上显示完整文字

时间:2014-05-23 06:02:36

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

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

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);
}

我的输出是这样的:

output

当我点击标记时,它不会显示全文。而不是它向我显示一些文字并在显示一些点之后。

Google Map V2中是否有任何方法可以显示全文?我已经使用了&#34; MarkerOptions&#34;的title()方法。类。

2 个答案:

答案 0 :(得分:3)

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

只需创建一个扩展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));

答案 1 :(得分:-1)

尝试以下代码

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

希望这会对你有所帮助

相关问题