gpt4 book ai didi

android - 如何通过 google map apis 从 JSON 响应中获取纬度/经度

转载 作者:搜寻专家 更新时间:2023-11-01 08:11:48 24 4
gpt4 key购买 nike

我无法正确提取纬度和经度点集以进一步绘制路线。任何人都可以为我提供这样做的代码吗?

提前致谢

最佳答案

public class MapprojectActivity extends MapActivity {
/** Called when the activity is first created. */
static final String TAG_RESULTS = "results";
static final String TAG_GEO = "geometry";
static final String TAG_LOCATION = "location";
static final String TAG_LAT = "lat";
static final String TAG_LNG = "lng";
JSONArray res = null;
MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
MyItemizedOverlay itemizedOverlay;
static String url = "http://maps.google.com/maps/api/geocode/json?address=guindy,+chennai,+IN&sensor=false";

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.map);
TextView lattv=(TextView)findViewById(R.id.lat);
TextView lngtv=(TextView)findViewById(R.id.lng);
JSONParstring jParser = new JSONParstring();

// getting JSON string from URL

try
{
JSONObject jobj = new JSONObject(json);

res = jobj.getJSONArray(TAG_RESULTS);
for(int i = 0; i < res.length(); i++){
JSONObject c = res.getJSONObject(i);

JSONObject loc = c.optJSONObject(TAG_GEO).optJSONObject(TAG_LOCATION);

String lat =loc.getString(TAG_LAT);

String lng = loc.getString(TAG_LNG);

lattv.setText(lat);
lngtv.setText(lng);

}
}
catch (JSONException e){ }
String i=(String) lattv.getText();
String j=(String) lngtv.getText();

double lat1 = Double.parseDouble(i);
double lng1 = Double.parseDouble(j);


mapView = (MapView) findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(false);

mapOverlays = mapView.getOverlays();
drawable = getResources().getDrawable(R.drawable.mark1);
itemizedOverlay = new MyItemizedOverlay(drawable, mapView);

GeoPoint point = new GeoPoint((int)(lat1*1E6),(int)(lng1*1E6));
OverlayItem overlayItem = new OverlayItem(point, "Amy Jones",
"(checked in Lemon-tree with friends lisa wong, paul jones)");
itemizedOverlay.addOverlay(overlayItem);

mapOverlays.add(itemizedOverlay);

final MapController mc = mapView.getController();
mc.animateTo(point);
mc.setZoom(16);
// Integer i = Integer.valueOf((String) lattv.getText());
// Integer j = Integer.valueOf((String) lngtv.getText());
// // first overlay


}

protected boolean isRouteDisplayed() {
return false;
}

}

关于android - 如何通过 google map apis 从 JSON 响应中获取纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8983164/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com