關於位置和鄰里的細節這裏是我的代碼如何讓解析網址在谷歌地圖獲得Android中
public static JSONObject getLocationInfo(String address) {
StringBuilder stringBuilder = new StringBuilder();
try {
// address = address.replaceAll(" ","%20");
HttpPost httppost = new HttpPost("http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false");
HttpClient client = new DefaultHttpClient();
HttpResponse response;
stringBuilder = new StringBuilder();
response = client.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
int b;
while ((b = stream.read()) != -1) {
stringBuilder.append((char) b);
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject = new JSONObject(stringBuilder.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonObject;
}
我得到一個JSON例外,在響應。請告訴我一個有效的網址。我也爲gps做過mapview(api key和android manifest許可)。
的logcat:
04-03 16:35:20.548: E/CheckinTask(202): java.net.UnknownHostException: android.clients.google.com
04-03 16:35:20.548: E/CheckinTask(202): at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
04-03 16:35:20.548: E/CheckinTask(202): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
04-03 16:35:20.548: E/CheckinTask(202): at java.net.InetAddress.getAllByName(InetAddress.java:256)
04-03 16:35:20.548: E/CheckinTask(202): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
04-03 16:35:20.548: E/CheckinTask(202): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
04-03 16:35:20.548: E/CheckinTask(202): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
04-03 16:35:20.548: E/CheckinTask(202): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
04-03 16:35:20.548: E/CheckinTask(202): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
04-03 16:35:20.548: E/CheckinTask(202): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
04-03 16:35:20.548: E/CheckinTask(202): at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:248)
04-03 16:35:20.548: E/CheckinTask(202): at com.google.android.common.http.GoogleHttpClient.executeWithoutRewriting(GoogleHttpClient.java:203)
04-03 16:35:20.548: E/CheckinTask(202): at com.google.android.common.http.GoogleHttpClient.execute(GoogleHttpClient.java:245)
04-03 16:35:20.548: E/CheckinTask(202): at com.google.android.common.http.GoogleHttpClient.execute(GoogleHttpClient.java:313)
04-03 16:35:20.548: E/CheckinTask(202): at com.google.android.gsf.checkin.CheckinTask.sendRequest(CheckinTask.java:254)
04-03 16:35:20.548: E/CheckinTask(202): at com.google.android.gsf.checkin.CheckinTask.doInBackground(CheckinTask.java:150)
04-03 16:35:20.548: E/CheckinTask(202): at com.google.android.gsf.checkin.CheckinService$1.doInBackground(CheckinService.java:221)
04-03 16:35:20.548: E/CheckinTask(202): at com.google.android.gsf.checkin.CheckinService$1.doInBackground(CheckinService.java:214)
04-03 16:35:20.548: E/CheckinTask(202): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-03 16:35:20.548: E/CheckinTask(202): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-03 16:35:20.548: E/CheckinTask(202): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-03 16:35:20.548: E/CheckinTask(202): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-03 16:35:20.548: E/CheckinTask(202): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-03 16:35:20.548: E/CheckinTask(202): at java.lang.Thread.run(Thread.java:1019)
粘貼錯誤日誌以供參考的URL是正確的獲取與給定字符串 – 2012-04-03 10:47:59
@divaNilisha匹配的所有地址,請參閱此鏈接https://developers.google.com/maps/documentation/地理編碼/#地理編碼響應,並且發佈您的logcat對我們很有幫助。 – 2012-04-03 11:00:46
如何在這裏把logcat錯誤,而不是評論,對不起,我是新來的。 – divaNilisha 2012-04-03 11:09:32