android - 如何通过谷歌地图API从JSON响应中获取纬度/经度

标签 android google-maps-mobile

我无法正确提取纬度和经度点集以进一步绘制路线。有人能给我代码吗?

提前致谢

最佳答案

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 - 如何通过谷歌地图API从JSON响应中获取纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8983164/

相关文章:

android - 将位图保存到磁盘时,实心路径显示伪影

android - 谷歌地图在 Android 上运行良好,但我仍然收到错误 "Could not find class ' maps.i.k',引用自方法 maps.z.ag.a"

javascript - 我应该在 Sencha-Touch 2 中的什么地方放置 Google map 逻辑?多重标记

iphone - 如何缩放添加到 uiwebview 的谷歌地图中的特定点?

java - Android Froyo : Connection to https using trusting all socket factory results in target server failed to respond

android - 从应用程序主屏幕切换到其他 Activity 时应用程序崩溃

android studio avd 管理器无效选项 -- '-enable-whpx'

android - Kotlin .TypeCastException : null cannot be cast to non-null type

android - 如何从 Google map 应用获取用户当前的 GPS 位置?

cordova - 谷歌地图上带有图标\标签的地理 URI