11

I'm using android studio.

I'm trying to get location name from googlemaps when clicked.

I'm using geocoder.

Everytime i click somewhere on the map , marker goes there but i cant get the city name and i get a grpc failed 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 failed W/System.err: at com.example.umut.googlemapstest.MapsActivity$override.onMapClick(MapsActivity.java:127)

Which shows

List<Address> city = geocoder.getFromLocation(latLng.latitude,latLng.longitude,1);

This code

6
  • 3
    Is this on an emulator or an actual device? There's a known problem with the Geocoder not working on the Android emulator.
    – AndrewR
    Aug 22, 2017 at 3:44
  • Yeap i'm using android studio emulator.I dont have an actual android device.Is there any alternatives ?
    – MePengusta
    Aug 22, 2017 at 13:10
  • 1
    There currently isn't any workaround for emulators unfortunately.
    – AndrewR
    Aug 23, 2017 at 23:48
  • 1
    Any luck with you? I have this issue in motorola device and it is working well with me on emulator.
    – M.SH
    Sep 10, 2017 at 13:18
  • I believe the problem with it not working on emulator should be fixed now.
    – AndrewR
    Sep 13, 2017 at 4:34

1 Answer 1

0

I have solution for exception "java.io.ioexception grpc failed":

try {
    Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
    List addresses = geocoder.getFromLocation(latitude, longitude, 1); 
    List<Address> addresslist = addresses;
    String address = addresslist.get(0).getAddressLine(0);
    Log.d("add",address);
} catch (IOException e) {
    e.printStackTrace();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.