I'm trying to display a new activity from a MapActivity
.
In fact, I want to open a new activity by clicking on the InfoWindow
of the Marker who are on my Map
I tried to use intent in an OnInfoWindowClick
Method but the application is still crashing when I click on an InfoWindow
This is my MapActivity :
public class MapsActivity extends FragmentActivity implements GoogleMap.OnMarkerClickListener, OnMapReadyCallback, GoogleMap.OnMapClickListener {
private GoogleMap mMap;
private Marker mMarker;
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(mMap.MAP_TYPE_NORMAL); // Here is where you set the map type
// Add a marker in Sydney and move the camera
LatLng dfltMarkLyon = new LatLng(45.760102,4.839177);
mMarker.setTag(0);
mMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(45.756363,4.833219)).title("L'Institut Restaurant").snippet("Restaurant").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
mMarker.setTag(1);
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(MapsActivity.this, "Test " + i, Toast.LENGTH_SHORT).show();
i += 1;
Intent intent = new Intent(MapsActivity.this, PlaceActivity.class);
startActivity(intent);
}
});
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
float zoomLevel = 13.0f; //This goes up to 21
mMap.setOnMapClickListener(this);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(dfltMarkLyon, zoomLevel));
}
And this is the class where is situated the activity I want to open :
public class PlaceActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_description);
//Toast.makeText(PlaceActivity.this, "New Class", Toast.LENGTH_SHORT).show();setContentView(R.layout.activity_description);
}
}
When I click on the InfoWindow
my application crash
What can I do to improve that?