私のアプリケーションでは、都市を提供することで、http://www.google.com/ig/api? weather=""を使用している天気予報を取得したいと思います。しかし、私にとっては緯度と経度しか利用できません
緯度と経度で地名を取得するにはどうすればよいですか。
私のアプリケーションでは、都市を提供することで、http://www.google.com/ig/api? weather=""を使用している天気予報を取得したいと思います。しかし、私にとっては緯度と経度しか利用できません
緯度と経度で地名を取得するにはどうすればよいですか。
参考までに、あなたがしていることは逆ジオコーディングと呼ばれています。
findNearbyを含め、ほとんどのGeonamesWebサービスはJSONで利用できます。
Googleには逆ジオコーディングWebサービスもあります
あなたが求めているのは小さなことではありません-lat/lngデータベースはほぼ確実にXMLまたはJSONで表示されるので、これに少し時間と労力を費やす価値があるかもしれません。Androidにはxml/jsonラッパーが必要ですか?
この天気APIでは、を呼び出す必要はありません。BTWは公開されていないため、Geocoder
注意して使用する必要があります。これは情報フィールドにすぎないため、次のように使用できます(ダミー定数)。city
state
country
private static final String URL = "http://www.google.com/ig/api?weather=%s,%s,%s,%d,%d";
//...
final String url = String.format(URL, "city", "state", "country",
p.getLatitudeE6(), p.getLongitudeE6());
Location APIを使用して、住所オブジェクトを取得し、そこから地域を取得できます
メソッドに緯度と経度を渡し、対応する地名を取得します。ユーザー権限を忘れないでください:
public static String getUserLocation(String lat, String lon) {
String userlocation = null;
String readUserFeed = readUserLocationFeed(lat.trim() + "," + lon.trim());
try {
JSONObject Strjson = new JSONObject(readUserFeed);
JSONArray jsonArray = new JSONArray(Strjson.getString("results"));
userlocation = jsonArray.getJSONObject(1)
.getString("formatted_address").toString();
} catch (Exception e) {
e.printStackTrace();
}
Log.i("User Location ", userlocation);
return userlocation;
}
public static String readUserLocationFeed(String address) {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"http://maps.google.com/maps/api/geocode/json?latlng=" + address
+ "&sensor=false");
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
Log.e(ReverseGeocode.class.toString(), "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}
Androidには、このようなもののためのGeocoderというクラスがあります。getFromLocation
メソッドを見てください。