0
我有一個活動,顯示從JSON文檔中檢索到的POI列表。當我點擊一個列表元素時,它會打開Google地圖應用程序並顯示地圖上的相對點。從JSON中檢索Google地圖位置時出錯
這適用於模擬器,但不適用於物理設備,因爲它尋找像xx,xxxxxxx這樣的座標而不是xx.xxxxxxx:它返回「找不到結果」錯誤。
請注意,設備的UI語言是意大利語。
這是JSON的一個樣本:
[
{
"id": "1",
"latitude": "48.8586006",
"longitude": "2.2939799",
"city": "Paris",
"description": "Tour Eiffel"
}
]
,這是從MyActivity片斷:
try {
JSONArray jarray = new JSONArray(loadJSON());
JSONObject jobject = jarray.getJSONObject(0);
String urlAddress = "http://maps.google.com/maps?q="+ jobject.getString("latitude") +"," + jobject.getString("longitude") +"("+ jobject.getString("description") + " - " + jobject.getString("city") + ")&iwloc=A&hl=it";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(urlAddress));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
break;
} catch (JSONException e) {
e.printStackTrace();
}