如何使用单个坐标突出显示前方1公里和1公里后方的道路

时间:2014-09-22 08:23:38

标签: android google-maps google-direction

让我说我有道理上存在的观点。现在我想强调使用该点的道路约1-1.5公里,如下图所示

enter image description here

任何解决方法如何做到这一点??

先谢谢。

1 个答案:

答案 0 :(得分:1)

这是代码。希望它有所帮助;

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