Possible Duplicate:
How to get complete address from latitude and longitude?
How to get location name in Android using Lattitude and Longitude till the City Name and street name
Possible Duplicate:
How to get complete address from latitude and longitude?
How to get location name in Android using Lattitude and Longitude till the City Name and street name
try this
private void getAddressGoogleQuery() {
String address = "";
try {
String URL = "http://maps.google.com/maps/geo?q=" + latitude + ","
+ longitude + "&output=csv";
String device_address = Get(URL);
String[] output = device_address.split("\"");
try {
address = output[1];
} catch (Exception e) {
// TODO: handle exception
}
Log.d("Activity", "Address:" + address);
} catch (Exception e) {
}
}
public static String Get(String URLStr) throws Exception
{
String resultStr = "";
BufferedReader in = null;
try
{
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(URLStr);
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
resultStr = sb.toString();
}
catch(Exception ee)
{
ee.printStackTrace();
}
finally
{
if (in != null)
{
try
{
in.close();
} catch (Exception e)
{
}
}
}
return resultStr;
}
You can achieve it using reverse geocoder. A sample code for that:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latValue,
longValue, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder(
"Address:\n");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress
.append(returnedAddress.getAddressLine(i)).append(
"\n");
}
myAddress.setText(strReturnedAddress.toString());
} else {
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myAddress.setText("Canont get Address!");
}
Just place this code after you are getting latitude and longitude values.