本文介绍了如何从JSON纬度/经度通过谷歌地图的API把响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能够正确地解压出来将进一步绘制路线的纬度和经度点。任何人都可以让我的code这样做呢?

在此先感谢


解决方案

 公共类MapprojectActivity扩展MapActivity {
    / **当第一次创建活动调用。 * /
    静态最后弦乐TAG_RESULTS =成果;
    静态最后弦乐TAG_GEO =几何体;
    静态最后弦乐TAG_LOCATION =地利;
    静态最后弦乐TAG_LAT =纬度;
    静态最后弦乐TAG_LNG =LNG
    JSONArray RES = NULL;
    MapView类MapView类;
    清单<&叠加GT; mapOverlays;
    可绘制可绘制;
    MyItemizedOverlay itemizedOverlay;
    静态字符串URL =htt​​p://maps.google.com/maps/api/geo$c$c/json?address=guindy,+chennai,+IN&sensor=false;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){        super.onCreate(savedInstanceState);
        的setContentView(R.layout.map);
        TextView的lattv =(的TextView)findViewById(R.id.lat);
        TextView的lngtv =(的TextView)findViewById(R.id.lng);
        JSONParstring jParser =新JSONParstring();        // URL从获取JSON字符串        尝试
        {
            JSONObject的jobj =新的JSONObject(JSON);            RES = jobj.getJSONArray(TAG_RESULTS);
            的for(int i = 0; I< res.length();我++){
                JSONObject的C = res.getJSONObject(I)                JSONObject的LOC = c.optJSONObject(TAG_GEO).optJSONObject(TAG_LOCATION);            字符串经纬度= loc.getString(TAG_LAT);            字符串LNG = loc.getString(TAG_LNG);            lattv.setText(LAT);
            lngtv.setText(LNG);            }
        }
        赶上(JSONException E){}
串I =(字符串)lattv.getText();
字符串J =(字符串)lngtv.getText();双LAT1 = Double.parseDouble(ⅰ);
双lng1 = Double.parseDouble(J);
        图形页面=(图形页面)findViewById(R.id.map_view);
        mapView.setBuiltInZoomControls(假);        mapOverlays =调用MapView.getOverlays();
    绘制= getResources()getDrawable(R.drawable.mark1)。
    itemizedOverlay =新MyItemizedOverlay(绘制,图形页面);    的GeoPoint点=新的GeoPoint((INT)(LAT1 * 1E6),(INT)(lng1 * 1E6));
    OverlayItem overlayItem =新OverlayItem(点,艾米·琼斯
            (在柠檬树检查与朋友丽莎王,保罗·琼斯));
    itemizedOverlay.addOverlay(overlayItem);    mapOverlays.add(itemizedOverlay);    最后MapController MC = mapView.getController();
    mc.animateTo(点);
    mc.setZoom(16);
//整数i = Integer.valueOf((字符串)lattv.getText());
//整数j = Integer.valueOf((字符串)lngtv.getText());
// //第一个叠加
    }    保护布尔isRouteDisplayed(){
        返回false;
    }}

I am not able to properly extract out the latitude and longitude point set to draw route further. Can anybody get me the code to do so?

Thanks in advance

解决方案
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;
    }

}

这篇关于如何从JSON纬度/经度通过谷歌地图的API把响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 11:16