简体   繁体   English

如何从谷歌地图API响应的JSON获取纬度/经度

[英]How to get Latitude/Longitude from JSON responsed by google map apis

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;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过在线json在Google地图上标记纬度和经度 - how to mark latitude and longitude on google map from an online json 如何从谷歌地图 URL 获取纬度经度 - How to get latitude longitude from google map URL 如何在Google地图上点击时获得经度和纬度 - How to get latitude & longitude onclick on google map 如何从地图中的标记获取纬度和经度 - How to get latitude and longitude from a mark in the map 从json文件获取经度和纬度并将点插入到Google Map-Android - Get latitude and longitude from json file and insert points to google map - Android 如何从Web服务动态获取Google地图(map_icon,标题,纬度,经度) - How to get Google map (map_icon, title, latitude, longitude) dynamically from webservice 如何在Google Map v2中获取标记的经度和纬度值 - How to get the longitude and latitude value of the marker in google map v2 Kotlin:如何获取经度和纬度以故意调用Google地图? - Kotlin: how to get a latitude and longitude to call google map with intent? 如何在Google Map(Android)中从mMap.setMyLocationEnabled(true)缩放并获取经纬度 - How to Zoom and get latitude and longitude from mMap.setMyLocationEnabled(true) in Google Map (Android) 如何在android studio中的谷歌地图上获取选定位置的纬度和经度 - How to get latitude and longitude of select location on google map in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM