I am a total newbie in android development, trying to learn here. I am trying to get the marker to show up on maps with a touch or tap which works, it also shows latitude and Longitude. I want to convert those latitude and Longitude into it's respective location name and I know it is possible with Reverse Geocoder but I just don't know how to code it right.
Here is my code.
public void onMapReady(final GoogleMap googleMap) {
mMap = googleMap;
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
String address;
String city;
mMap.clear();
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());
try {
addresses = geocoder.getFromLocation(point.latitude, point.longitude, 1);
address = addresses.get(0).getAddressLine(0);
city = addresses.get(0).getLocality();
MarkerOptions markerOptions = new MarkerOptions()
.position(point)
.title(city);
Marker marker = mMap.addMarker(markerOptions);
marker.showInfoWindow();
} catch (IOException e) {
e.printStackTrace();
}
}
});}