I am new to android and i want to display my current location like "johar town Lahore, Pakistan". Any help please ?
thanks in advance.
I am new to android and i want to display my current location like "johar town Lahore, Pakistan". Any help please ?
thanks in advance.
to get current latitude and longitude use: LocationManager
LocationManager locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria cr = new Criteria();
String provider = locationmanager.getBestProvider(cr, true);
Location location = locationmanager.getLastKnownLocation(provider);
if (location != null) {
double lat=location.getLatitude();
double lng=location.getLongitude();
}
pass current latitude and longitude to following method it will return you address !
public List<Address> getAddress(double latitude, double longitude) {
List<Address> addresses = null;
try {
Geocoder geocoder;
geocoder = new Geocoder(youractivityname.this);
if (latitude != 0 || longitude != 0) {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
//testing address below
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
Log.d("TAG", "address = " + address + ", city =" + city
+ ", country = " + country);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
// Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
return addresses;
}
First of all you have to find your location, so follow this posts: Current location and here Current location.
Then to find places, have a look here List of places around user