I need to get the user current city name. If getting the city name with AGPS or anything is good. I need the method or code for getting the current city in android. Please share if you know.
Asked
Active
Viewed 1.4k times
2 Answers
22
This one is for getting location name from current lat,long
Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(lat, lng, 1);
if (addresses.size() > 0)
System.out.println(addresses.get(0).getLocality());

user370305
- 108,599
- 23
- 164
- 151
-
I tried with you code its not working. i have added internet permission and access fine location permission. do i need to add any more permissions. – arnp Nov 14 '11 at 09:32
-
1try{ Geocoder gcd = new Geocoder(context, Locale.getDefault()); List addresses = gcd.getFromLocation(16.045813,76.992188, 1); if (addresses.size() > 0) strlocation = String.valueOf(addresses.get(0).getLocality()); Toast.makeText(this, strlocation, Toast.LENGTH_SHORT).show(); }catch(Exception e) { e.printStackTrace(); } – arnp Nov 14 '11 at 09:41
-
java.lang.ClassNotFoundException: com.andro.loc.LocfinderActivity in loader dalvik.system.PathClassLoader[/data/app/com.andro.loc-2.apk] – arnp Nov 14 '11 at 10:04
-
Its your activity class not found in DVM. its not a geocoder exception, Have you mentioned activity name in manifest file. if yes then remove application from emulator and re-install it and if not then just add it in manifest. – user370305 Nov 14 '11 at 10:09
-
I am getting error which says "Timed out waiting for response from server". I have added Internet permission. Do it need something else? – Bhaumik Belani Apr 26 '16 at 17:34