I am using android studio.
I am trying to get location name from googlemaps when clicked.
I am using a geocoder.
Every time I click somewhere on the map, the marker goes there, but I canβt get the name of the city, and I get an error with grpc error.
What should I do? I tried this with api 23,24,25 , none of them worked.
My onMapClick function:
@Override public void onMapClick(LatLng latLng) { mMap.clear(); mMap.addMarker(new MarkerOptions().position(latLng).title("Konum")); mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); Geocoder geocoder = new Geocoder(MapsActivity.this.getBaseContext(), Locale.getDefault()); try { List<Address> city = geocoder.getFromLocation(latLng.latitude,latLng.longitude,1); if (city != null && city.size() > 0){ Log.i("Info",city.get(0).getLocality()); } } catch (IOException e) { e.printStackTrace(); } }
W / System.err: java.io.IOException: grpc error W / System.err: at com.example.umut.googlemapstest.MapsActivity $ override.onMapClick (MapsActivity.java:127)
What shows
List<Address> city = geocoder.getFromLocation(latLng.latitude,latLng.longitude,1);
This code
java android google-maps
MePengusta
source share