![](/img/trans.png)
[英]Java Android AlertDialogs Show on infowindow OnClick for google maps v2
[英]Google maps android V2: how to pan map to show InfoWindow
我有一个带有自定义Infowindow的地图,我想确保每次用户单击标记时,信息窗口将完全可见,我该怎么做?
我已经有一些代码来防止以单击标记为中心,但是我不知道如何做我需要做的事情:
private void preventMarkerCenter(){
map.setOnMarkerClickListener(new OnMarkerClickListener() {
public boolean onMarkerClick(Marker marker) {
// Check if there is an open info window
if (lastOpenned != null) {
// Close the info window
lastOpenned.hideInfoWindow();
// Is the marker the same marker that was already open
if (lastOpenned.equals(marker)) {
// Nullify the lastOpenned object
lastOpenned = null;
// Return so that the info window isn't openned again
return true;
}
}
// Open the info window for the marker
marker.showInfoWindow();
// Re-assign the last openned such that we can close it later
lastOpenned = marker;
// Event was handled by our code do not launch default behaviour.
return true;
}
});
}
根据文档: http : //developer.android.com/reference/com/google/android/gms/maps/GoogleMap.OnMarkerClickListener.html
通过返回true
阻止的“默认行为”是显示信息窗口,然后将地图居中在标记上。
我认为,如果不调用marker.showInfoWindow()
并返回false
,则会得到想要的结果。
如果要平移地图以显示信息窗口,则必须自己进行计算,然后使用CameraUpdateFactory
平移地图。 CameraUpdateFactory.scrollBy()
或类似的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.