0

有人知道根据什么谷歌地图选择行车路线吗?

高速路之类的...

我在我的应用程序中使用谷歌地图 v2 方向,我想知道它根据什么来调整方向。

4

1 回答 1

1

根据谷歌的说法,你可以避开高速公路、渡轮和收费站。您也可以选择模式,但不能选择“快速道路”。
例如:

http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false&key=API_KEY&avoid=highways&mode=driving

对于您的应用程序,您可以这样做:

String url = "http://maps.googleapis.com/maps/api/directions/xml?origin=Toronto&destination=Montreal&sensor=false&key=API_KEY&avoid=highways&mode=driving";
HttpGet httpGet = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse;
try {
    httpResponse = httpClient.execute(httpGet);
    HttpEntity httpEntity = httpResponse.getEntity();
    InputStream inputStream = httpEntity.getContent();

    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(inputStream);
    //In doc is your response
} catch (Exception e) {
    e.printStackTrace();
}
于 2014-04-16T13:26:01.387 回答