重複の可能性:
緯度と経度から完全な住所を取得するには?
都市名と通り名まで緯度と経度を使用してAndroidで場所名を取得する方法
これを試して
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;
}
逆ジオコーダーを使用して実現できます。そのためのサンプルコード:
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!");
}
緯度と経度の値を取得した後に、このコードを配置するだけです。
Geocoderクラスを使用して、都市や国の情報などの情報を取得できます。
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);