我在 map 上有多个标记及其信息。通过点击特定标记,它会显示信息。 下面是添加多个标记的代码:
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()
方法。
最佳答案
感谢您的帮助。但我解决了我的问题。
只需创建一个扩展 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));
关于android - map 标记标题在 Google map V2 上不显示全文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23822004/