我想在infowindow中添加一个图像,我已经看到了一些例子但不太了解。 这是我的代码
public class MainActivity extends FragmentActivity {
GoogleMap gmap;
LatLng latlng=null;
String result=null;
final MarkerOptions marker_options=new MarkerOptions();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gmap=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.gmap)).getMap();
gmap.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
latlng=point;
new CityAsyncTask(latlng).execute();
}
});
gmap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view=getLayoutInflater().inflate(R.layout.info_iamge_window, null);
LatLng position=marker.getPosition();
TextView txt_info_image=(TextView) findViewById(R.id.txt_image);
ImageView img_view=(ImageView)findViewById(R.id.info_image);
txt_info_image.setText(marker.getTitle());
return view;
}
});
}
class CityAsyncTask extends AsyncTask<String, String, String>
{ public CityAsyncTask(LatLng latlng_points) {
latlng=latlng_points;
System.out.println("latlng points are:::::"+latlng);
}
@Override
protected String doInBackground(String... params) {
Geocoder gcoder=new Geocoder(MainActivity.this,Locale.getDefault());
try
{
List<Address> addresses=gcoder.getFromLocation(latlng.latitude, latlng.longitude,1);
Log.e("Addresses "," :: "+addresses);
StringBuilder sb=new StringBuilder();
if(addresses.size()>0)
{
Address address=addresses.get(0);
sb.append(address.getAddressLine(0)).append("\n");
sb.append(address.getCountryName());
}
result=sb.toString();
}catch(IOException e)
{
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
marker_options.position(latlng);
marker_options.title(result);
marker_options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
Marker marker=gmap.addMarker(marker_options);
marker.showInfoWindow();
}
}
}