我正在尝试在Android上使用GoogleMap API,但我希望在用户点击丢弃的图钉时隐藏infoWindow。然而,我仍然希望显示方向和latlog图标。
换句话说,图片应该澄清我需要的东西:
我试图在我丢弃的引脚上添加一个监听器,但这会杀死整个infoWindow和方向图标,如下:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng location1 = new LatLng(32.75613, -117.11648);
mMap.addMarker(new MarkerOptions().position(location1).title("Hello"));
LatLng location2 = new LatLng(32.754978528015876, -117.12977170944214);
mMap.addMarker(new MarkerOptions().position(location2).title("World"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location1, 12.0f)); //zoom out
// This does not work, if I turn it to true, I loose the directions icon
// I don't want a custom info window, I just want to hide it and have the directions
// icon still showing up
if (false) {
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Log.d("zzz", "marker = " + marker.getTitle());
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 14.0f)); //zoom out
return true;
}
});
}
}
是否可以这样做,而无需重写方向图标的整个逻辑?
THX!
答案 0 :(得分:2)
更好的解决方案,只是让屏幕上显示出一个点。
private static final float ACHOR_WINDOWS_U = -9999;
private static final float ACHOR_WINDOWS_V = -9999;
...
Marker marker = map.addMarker(markerOptions);
marker.setInfoWindowAnchor(ACHOR_WINDOWS_U, ACHOR_WINDOWS_V);
答案 1 :(得分:0)
试试这个
map.addMarker(new MarkerOptions().position(new LatLng(0, 0)));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 14.0f));
return false;
}
});