I am using Google Map API V2 and i have created a custom InfoWindow for a Marker on map.In this InfoWindow i have a button.
My
You have to implement Custom marker; It is like this:
custommarker.xml
Activity:
public class PlacesMapActivity extends android.support.v4.app.FragmentActivity
implements OnClickListener, LocationListener {
/**
* Note that this may be null if the Google Play services APK is not
* available.
*/
ImageButton btn_home;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
SupportMapFragment fragment = (SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
mMap = fragment.getMap();
mMap.setMyLocationEnabled(true);
// mMap = ((SupportMapFragment) getSupportFragmentManager()
// .findFragmentById(R.id.map)).getMap();
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.title("First Location");
markerOptions.snippet("This Is Test Location");
LatLng latlng = new LatLng(23.0333, 72.6167);
markerOptions.position(latlng);
// markerOptions.title("Ahmedabad Cordinat Found here");
// Marker m = mMap.addMarker(markerOptions);
***mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View myContentView = getLayoutInflater().inflate(
R.layout.custommarker, null);
TextView tvTitle = ((TextView) myContentView
.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());
TextView tvSnippet = ((TextView) myContentView
.findViewById(R.id.snippet));
tvSnippet.setText(marker.getSnippet());
return myContentView;
}
});***
mMap.addMarker(new MarkerOptions()
.position(latlng)
.title("This is Sabarmati Ashram")
.snippet("Ahmedabad")
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(getBaseContext(),
DetailsOfPlacesActivity.class);
startActivity(intent);
}
});
btn_home = (ImageButton) findViewById(R.id.activity_map_ibtn_home);
btn_home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
}