-1

我正在创建一个应用程序,我正在使用谷歌地图用户可以绘制路线并获取方向一切进展顺利,但问题是我如何从 html_instruction 逐步获得方向,如下所示:

"legs" : [
        {
           "distance" : {
              "text" : "6.0 km",
              "value" : 6020
           },
           "duration" : {
              "text" : "1 hour 15 mins",
              "value" : 4514
           },
           "end_address" : "MH Road, Rawalpindi, Pakistan",
           "end_location" : {
              "lat" : 33.5955202,
              "lng" : 73.044865
           },
           "start_address" : "4th Road, Rawalpindi, Pakistan",
           "start_location" : {
              "lat" : 33.6377411,
              "lng" : 73.0647159
           },
           "steps" : [
              {
                 "distance" : {
                    "text" : "23 m",
                    "value" : 23
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 15
                 },
                 "end_location" : {
                    "lat" : 33.6375325,
                    "lng" : 73.06468649999999
                 },
                 "html_instructions" : "Head \u003cb\u003esouth\u003c/b\u003e toward \u003cb\u003e4th Rd\u003c/b\u003e",
                 "polyline" : {
                    "points" : "{zhlEom}|Lf@D@?"
                 },
                 "start_location" : {
                    "lat" : 33.6377411,
                    "lng" : 73.0647159
                 },
                 "travel_mode" : "WALKING"
              },

我在做这个

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

但它的抛出异常

org.xml.sax.SAXParseException: Unexpected token (position:TEXT {

我如何解决它或以任何其他方式使用 google mapsv2 获取逐步指示

提前致谢

4

1 回答 1

0

如果 JSON 有Unexpected token,它可能有一个未显示的不可打印字符。尝试将您的原始文本复制并粘贴到hex dump website 此处,并与您获得的内容进行比较。

于 2015-02-27T04:22:52.050 回答