Snap to Roads Android

强颜欢笑 提交于 2019-11-29 07:54:16

Your URL seems to work perfectly.

Here is the AsyncTask I used to test it.

public class SnapToRoad extends AsyncTask<Void, Void, Void> {

private static final String TAG = SnapToRoad.class.getSimpleName();

@Override
protected Void doInBackground(Void... params) {
    Reader rd = null;
    try {
        URL url = new URL("http://maps.google.com/maps/api/directions/xml?origin=52.0,0&destination=52.0,0&sensor=true");
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setReadTimeout(10000 /* milliseconds */);
        con.setConnectTimeout(15000 /* milliseconds */);
        con.connect();
        if (con.getResponseCode() == 200) {

            rd = new InputStreamReader(con.getInputStream());
            StringBuffer sb = new StringBuffer();
            final char[] buf = new char[1024];
            int read;
            while ((read = rd.read(buf)) > 0) {
                sb.append(buf, 0, read);
            }
            Log.v(TAG, sb.toString());
        } 
        con.disconnect();
    } catch (Exception e) {
        Log.e("foo", "bar", e);
    } finally {
        if (rd != null) {
            try {
                rd.close();
            } catch (IOException e) {
                Log.e(TAG, "", e);
            }
        }
    }
    return null;
}

Within the logcat output if you look down a few lines you should see:

11-07 16:20:42.880: V/SnapToRoad(13920):     <start_location>
11-07 16:20:42.880: V/SnapToRoad(13920):      <lat>51.9999900</lat>
11-07 16:20:42.880: V/SnapToRoad(13920):      <lng>0.0064800</lng>
11-07 16:20:42.880: V/SnapToRoad(13920):     </start_location>

They are the coordinates you are looking for. I hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!