我已經從一個 URL 解析了一些 XML 數據,以顯示在 Android 設備上的列表視圖中。由于本網站上人們的一些研究和幫助,它按預期工作。我現在想要做的是獲取這些坐標并將地圖添加到我的項目中并創建一個單擊事件偵聽器函數,以便當我單擊一組特定的數據時它可以顯示在地圖上......我不是確定如何繼續進行此操作。我最終希望可以選擇一次選擇一個以在地圖上查看,以及具有所有坐標的更大地圖視圖我將發布我當前的結果和為我獲取 XML 數據的代碼。任何幫助將不勝感激。當前結果項目類的一部分public void setLat(Double lat) { this.lat = lat; } public Double getLon() { return lon; } public void setLon(Double lon) { this.lon = lon; } @Override public String toString() { return (new StringBuilder()).append("title: \n").append(title).append("\n") .append("link: ").append(link).append("\n") .append("geo-lat: ").append(lat).append("\n") .append("geo-lon: ").append(lon).toString(); }}主要活動課的一部分 } else if (xpp.getName().equalsIgnoreCase("geo:lat")) { if (insideItem) { //extract the text between <geo:lat> and </geo:lat> item.setLat(Double.valueOf(xpp.nextText())); } } else if (xpp.getName().equalsIgnoreCase("geo:long")) { if (insideItem) { //extract the text between <geo:lat> and </geo:lat> item.setLon(Double.valueOf(xpp.nextText())); } } }我只是不知道如何使用這些返回值在我的 android 項目中填充地圖
1 回答
呼如林
TA貢獻1798條經驗 獲得超3個贊
您需要生成一個 Google Maps API 密鑰。
放置一個 ImageView 并將此 URL 加載到該 ImageView 中:
https://maps.google.com/maps/api/staticmap?center=latitude,longitude&zoom=15&size=1280x720&sensor=false&markers=latitude,longitude&key=YOUR_API_KEY
在你的按鈕上OnClickListener():
String uri = String.format(Locale.ENGLISH, "geo:%f,%f?q=%f,%f",
latitude,
longitude,
latitude,
longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
這會將 Google 地圖應用程序打開到這些坐標。
添加回答
舉報
0/150
提交
取消
