I am currently working on an Android studio app where I need a map. In this map I have a button called, add marker. What I want to do with this button is to display a marker in my current location whenever I press it.
To do that I have the next method:
private void drawMarker(Location location) {
if (mMap != null) {
mMap.clear();
LatLng gps = new LatLng(location.getLatitude(), location.getLongitude());
mMap.addMarker(new MarkerOptions().position(gps));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(gps, 16));
}
}
The problem with this method is that its parameter is Location location so whenever I initialize the app and press on it, my app will stop and an error will show. I think this is because my parameter should be View view.
This is the error: java.lang.IllegalStateException: Could not find a method drawMarker(View) in the activity class com.naluapp.naluapp.MapsActivity for onClick handler on view class android.widget.Button with id 'addMarker
I tried to resolve this by putting a variable Location location in my map activity but that does no resolve my problem. I am no good at this kind of language so I need of your help. Do you know how to resolve this?