我正在使用Google Maps Api从Adress获取Lat和Lng,我构建了一个类,将json中的结果转换为Object,但工作正常,但我想获得纬度和经度,但我不能得到。这是我的代码,他们都有Getters和Setters,我只是不会放在这里。
public class RootObject {
public List<Result> results;
public String status;
public class Result {
public List<AddressComponent> address_components;
public String formatted_address;
public Geometry geometry;
public String place_id;
public List<String> types;
public class Geometry {
public Location location;
public String location_type;
public Viewport viewport;
在这里,我想得到这些价值观:
public class Location {
private double lat;
private double lng;
答案 0 :(得分:0)
如果你的问题只是“如何迭代列表”,你可以试试这个。
for (Result result : rootObject.getResults()) {
Location loc = result.getGeometry().getLocation();
Log.d("lon", loc.getLng());
Log.d("lat", lat.getLat());
}