enter code here
如何将按钮放在地图信息窗口并使其可点击,我尝试了以下代码: -
`enter code here`if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.animateCamera(CameraUpdateFactory.zoomTo(11.0f));
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
} else {
// final Get_Preference_model item =
// this.countryList.get(position);
for(int i=0;i<countryList.size();i++)
{
sfLatLng = new LatLng(Double.parseDouble(countryList.get(i).latitude),Double.parseDouble(countryList.get(i).longitude));
//sfLatLng = new LatLng(dblatt, dblong);
String buname = countryList.get(i).deal_id+"-"+countryList.get(i).deal_name;
Marker marker = googleMap.addMarker(new MarkerOptions()
.position(sfLatLng)
.title(buname)
.snippet(countryList.get(i).deal_description)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.imgmapfullredpin)));
dlid = countryList.get(i).deal_id;
dlname = countryList.get(i).deal_name;
catname = countryList.get(i).category_name;
dldesc = countryList.get(i).deal_description;
distan = countryList.get(i).distance;
retailadd = countryList.get(i).retailer_address;
dllat = countryList.get(i).latitude;
dllng = countryList.get(i).longitude;
totdeal = countryList.get(i).totdeals;
}
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
public View getInfoWindow(Marker m1) {
View v = getLayoutInflater().inflate(
R.layout.balloon_map_overlay, null);
TextView tite = (TextView) v
.findViewById(R.id.textView2);
TextView snip = (TextView) v
.findViewById(R.id.textView3);
if (m1.getTitle() != null) {
String str=m1.getTitle();
String[] strsg = str.split("-");
System.out.println(strsg[0]);
strpassid=strsg[0].toString();
System.out.println(strsg[1]);
tite.setText(strsg[1]);
//tite.setText(m1.getTitle());
}
if (m1.getSnippet() != null) {
String strh=m1.getSnippet();
System.out.println(strh);
snip.setText(m1.getSnippet());
//snip.setText(m1.getSnippet());
}
return v;
}
public View getInfoContents(Marker marker) {
return null;
}
});
googleMap
.setOnCameraChangeListener(new OnCameraChangeListener() {
public void onCameraChange(CameraPosition arg0) {
googleMap.animateCamera(CameraUpdateFactory
.newLatLng(sfLatLng));
googleMap.setOnCameraChangeListener(null);
}
});
googleMap
.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker item) {
// TODO Auto-generated method stub
Intent viewdeal = new Intent(
getApplicationContext(), ViewDealMap.class);
viewdeal.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
viewdeal.putExtra("dealid", strpassid);
startActivity(viewdeal);
overridePendingTransition(
R.anim.slide_in_right,
R.anim.slide_out_left);
}
});
}
}}
答案 0 :(得分:0)
//为Google地图设置自定义信息窗口适配器 googleMap.setInfoWindowAdapter(new InfoWindowAdapter(){
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker arg0) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);
// Getting reference to the TextView to set longitude
TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
// Setting the longitude
tvLng.setText("any text");
// declare a button wit onclick listener
// Returning the view containing InfoWindow contents
return v;
}
});