我有一个活动,显示从JSON文档中检索到的POI列表。当我点按列表元素时,它会打开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();
}
答案 0 :(得分:0)
非常奇怪的情况,加载你的json:
private String loadJSON(){
return "[{\"id\": \"1\","+
"\"latitude\": \"48.8586006\","+
"\"longitude\": \"2.2939799\","+
"\"city\": \"Paris\","+
"\"description\": \"Tour Eiffel\""+
"}];";
}
使用方法:
private void loadGoogleMap(){
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";
Log.e(TAG, "urlAddress : " + urlAddress);
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);
} catch (JSONException e) {
e.printStackTrace();
}
}
将此网址加载到Google地图中:
http://maps.google.com/maps?q=48.8586006,2.2939799(Tour埃菲尔 - 巴黎)& iwloc = A& hl = it
我认为这一定是与缓存相关的问题,请尝试清除Google地图缓存!