0
我想要創建一個android應用程序,在用戶當前位置附近繪製地圖上的建築。截至目前,我能夠執行請求並打印除lat和lng值之外的響應(例如id,名稱,附近等)。
我確信,我收到應答所需,你可以從這個logcat的消息看:使用Java客戶端API解析Lat/Lng的地方API
以下是我如何訪問/打印檢索值:
- 如前所述在註釋行中,訪問'for'中的'name'的代碼的第一行工作,而第二行不行。
@Override
protected void onPostExecute(PlacesList result) {
// TODO Auto-generated method stub
String text = "Result \n";
if (result!=null){
for(Place place: result.results) {
// This works
text = text + place.name +"\n";
// This doesn't
text = text + place.geometry.location.lat +"\n";
}
txt1.setText(text);
}
setProgressBarIndeterminateVisibility(false);
}
我猜問題可能是由該模型的方式(來源:link)造成被處理:
- 需要注意的是聲明(和離開它可能很重要未評論)公共幾何幾何;完全阻止我檢索任何響應值(id,名稱等)。
public class PlacesList {
@Key
public String status;
@Key
public List<Place> results;
}
public class Place {
@Key
public String id;
@Key
public String name;
@Key
public String reference;
@Key
public String vicinity;
@Key
public String icon;
// Leaving this line prevents me from retrieving any of the above values
@Key
public Geometry geometry;
// On the other hand, declaring non-existing elements (elements that are not
// included on the Place Search response) does not break the program
// at all (i.e. values from valid elements such as id, name, etc. can be retrieved)
@Key
public String testFakeElement;
@Override
public String toString() {
return name + " - " + id + " - " + reference;
}
}
public class Geometry {
@Key
public Location location;
@Override
public String toString() {
return location.toString();
}
public class Location {
@Key
public double lat;
@Key
public double lng;
@Override
public String toString() {
return Double.toString(lat) + ", " + Double.toString(lng);
}
}
}
任何成功的問題 – Ishu 2012-04-02 02:55:16
@DilSe它的工作現在。在下面檢查我的答案。 – 2012-04-03 03:38:43