私はアンドロイド用のアプリを作っています。Google マップのリバース ジオコーダーを使用して一連の座標をリバース ジオコーディングし、返された JSON を解析して都市名を抽出しています。しかし、「ニューヨーク」のような都市名の代わりに、それは戻ってきていますcom.example.geocoding_example.ParsingAsyncClass@418efd90(4025)
本当の答えではなく、これを得るために何が間違っていますか? ありがとう。
ParsingAsyncClass は次のとおりです。
package com.example.gecoding_example;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.json.JSONArray;
import org.json.JSONObject;
import android.net.http.AndroidHttpClient;
import android.os.AsyncTask;
import android.util.Log;
public class ParsingAsyncClass extends AsyncTask {
String cityName = null;
@Override
protected String doInBackground(Object... arg0)
{double latitude=40.7130;
double longitude=74.0135;
final AndroidHttpClient ANDROID_HTTP_CLIENT = AndroidHttpClient.newInstance(GecodingActivity.class.getName());
String googleMapUrl = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" +latitude + ","
+longitude + "&sensor=false&language=fr";
try
{
JSONObject googleMapResponse = new JSONObject(ANDROID_HTTP_CLIENT.execute(new HttpGet(googleMapUrl),
new BasicResponseHandler()));
// many nested loops.. not great -> use expression instead
// loop among all results
JSONArray results = (JSONArray) googleMapResponse.get("results");
for (int i = 0; i < results.length(); i++)
{
// loop among all addresses within this result
JSONObject result = results.getJSONObject(i);
if (result.has("address_components"))
{
JSONArray addressComponents = result.getJSONArray("address_components");
// loop among all address component to find a 'locality' or 'sublocality'
for (int j = 0; j < addressComponents.length(); j++)
{
JSONObject addressComponent = addressComponents.getJSONObject(j);
if (result.has("types"))
{
JSONArray types = addressComponent.getJSONArray("types");
// search for locality and sublocality
for (int k = 0; k < types.length(); k++)
{
if ("locality".equals(types.getString(k)) && cityName == null)
{
if (addressComponent.has("long_name"))
{
cityName = addressComponent.getString("long_name");
}
else if (addressComponent.has("short_name"))
{
cityName = addressComponent.getString("short_name");
}
}
if ("sublocality".equals(types.getString(k)))
{
if (addressComponent.has("long_name"))
{
cityName = addressComponent.getString("long_name");
}
else if (addressComponent.has("short_name"))
{
cityName = addressComponent.getString("short_name");
}
}
}
if (cityName != null)
{
Log.d("Geoco== "+cityName, "tag");
return cityName;
}
}
}
}
}
}
catch (Exception e)
{
Log.d(e.toString(),"tag");
}
return null;
}
@Override
protected void onPostExecute(Object cityaName){
super.onPostExecute(cityaName);
String a;
a=cityaName.toString();
if (cityaName != null)
{
// Do something with cityName
Log.d("GeocoderHelpe123" +
"r"+cityaName, "tag");
}else{Log.d("GeocoderHelper232"+cityaName, "tag");}
}
}