朋友你好。当我在地图上点击特定标记时,我想在地图v2中隐藏我的弹出窗口。 下面是我的代码:
public class DemopMap extends FragmentActivity {
GoogleMap googleMap;
Button button1;
Marker startPerc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demomap);
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
@SuppressLint("NewApi")
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
startPerc = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(62.2270,105.3809))
.title("Demo"));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(62.2270,105.3809), 5.0f));
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker marker) {
marker.hideInfoWindow();
Toast.makeText(getApplicationContext(), "InfoWindowAdapter", 2000).show();
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file info_window_layout
marker.hideInfoWindow();
View v = getLayoutInflater().inflate(R.layout.row_map, null);
v.setVisibility(View.GONE);
// Getting reference to the TextView to set title
TextView note = (TextView) v.findViewById(R.id.textView1);
TextView snip = (TextView) v.findViewById(R.id.textView2);
snip.setVisibility(View.GONE);
return v;
}
});
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
}
标记的行文件
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
当我点击标记时,我显示如下:
所以任何想法如何解决这个问题?
答案 0 :(得分:0)
我只是添加这一行,它对我有用
googleMap.setOnMarkerClickListener(new OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
arg0.hideInfoWindow();
return true;
}
});