0

我正在尝试在我的 fragmentMap 上绘制路线;当我“给”谷歌只有起点和终点时,一切都很好;但是当我尝试添加几个航点时,它失败了!

这是代码,希望你能给我一个解决方案,我快疯了!非常感谢

    String waypoints = "";
    String wayp= "&waypoints=";
    if(lp.size()>2){
    for(int i=1;i<lp.size()-1;i++){
        LatLng point  = lp.get(i).getLoc();
        waypoints += point.latitude + "," + point.longitude+ "|";
    }
    }else{
        waypoints = "";
    }
    wayp +=waypoints;
    Log.v("MAPPA", wayp);
    String url = "http://maps.googleapis.com/maps/api/directions/xml?" 
            + "origin=" + start.latitude + "," + start.longitude  
            +wayp+ "&destination=" + end.latitude + "," + end.longitude 
            + "&sensor=false&units=metric&mode=driving";

    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse response = httpClient.execute(httpPost, localContext);
        InputStream in = response.getEntity().getContent();
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(in);
        return doc;
    } catch (Exception e) {
        Log.v("MAPPA", "CATCH");
        e.printStackTrace();
    }

一直在抓!

4

0 回答 0