Currently doing a simple app that contain google map. and i would like to link to next activity when the user click on a designed coordinate but it is not working and there is no error, please help me
double latitude = 1.34503109;
double longitude = 103.94008398;
LatLng latLng = new LatLng(latitude, longitude);
gMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
Intent i = new Intent(Activity_Selecting_Bus.this,
Activity_Bus_Selected.class);
startActivity(i);
}
});
If I understand correctly you have markers set up in your map and when user clicks on a marker you start another activity. The following code should work (in
SupportMapFragment
):If you don't have markers and want to listen for a certain location click use this instead:
In this case you probably want to start the activity when the user clicks "close enough" to a certain location. I use this library http://googlemaps.github.io/android-maps-utils/ which contains method
which returns distance between two
LatLng
s in meters.EDIT Example:
First you define where the user has to click and which activity does that particular click launch:
Then when the user clicks on the map, you compute distance to each point. If it fits, you launch the activity.