0

I am a newbie in android. What I'm trying to do is to get a location by name, but I can't use this code in my android application.

String location = "London";

the code below is highlighted by red line saying "Cannot make a static reference to the non-static method getFromLocationName(String, int) from the type Geocoder"

-->>List<Address> addressList = Geocoder.getFromLocationName(location, 1);
Deepak Swami
  • 3,838
  • 1
  • 31
  • 46
user1570222
  • 93
  • 2
  • 3
  • 12

2 Answers2

2
 location="ahmedabad,gujarat,india";

 Geocoder gcd = new Geocoder(this, Locale.getDefault());

        try {
            addresses = gcd.getFromLocation(location, 1);
            if (addresses.size() > 0)
                for (int k = 0; k < addresses.size(); k++) {
                    locationname = addresses.get(k).getAddressLine(0);
                    Log.i("location name", locationname);
                }
        } catch (IOException e) {
            e.printStackTrace();
        }

Its A complate Example ANd Also Successfull Running In My Apps...All the Best

ckpatel
  • 1,926
  • 4
  • 18
  • 34
1

try this...

Geocoder geo = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> addressList= geo.getFromLocationName("London",10)
Mehul Santoki
  • 1,208
  • 1
  • 12
  • 25