Reputation: 21919
I want to dispaly the current location in my application not in map. I want the current palce using current lattitude and longitude . For Ex some 'x' person i want to know his location.but i want to know his location using his current lattitude and longitude. When i use the below code it`Context context;
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
List<android.location.Address> addresses = geoCoder.getFromLocation(17.385044,78.486671, 1);
String addr = "";
if (addresses.size() > 0)
{
for (int k=0; i<addresses.get(0).getMaxAddressLineIndex();
k++)
addr += addresses.get(0).getAddressLine(i) + "\n";
}
Toast.makeText(getBaseContext(), addr, Toast.LENGTH_SHORT).show();
Log.v("People","##############"+addr);
The "addr" does not getting any value.why it is happened here my Activity is extended by MapActivity and also tell me without extending activity (simply in class) how do you find the current location using current lattitude and longitude ?
please give me the code suggestions for this.Thanks in advance
Upvotes: 1
Views: 1101
Reputation: 74064
Use Geocoder class and call getFromLocation
method.
This snippet Toast your current location starting from latitude and longitude:
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0)
Toast.makeText(getBaseContext(),addresses.get(0).getLocality());
Upvotes: 0
Reputation: 185852
Use the android.location
package. There's a brief guide to using it here.
Upvotes: 1