android - 无法在 android 中打开来自 google map api 的流?

标签 android api

当我使用下面的 url 在 android 上的 map 上绘制路线时:

StringBuilder urlString = new StringBuilder();   
   urlString.append("http://maps.google.com/maps?f=d&hl=en");  
   urlString.append("&saddr=");  
   urlString.append(src);  
   urlString.append("&daddr=");// to  
   urlString.append(dest);  
   urlString.append("&ie=UTF8&0&om=0&output=kml");

调用 urlConnection.getInputStream 时抛出异常

HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
      urlConnection.setRequestMethod("GET");
      urlConnection.setDoOutput(true);
      urlConnection.setDoInput(true);
      urlConnection.connect(); 

      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      doc = db.parse(urlConnection.getInputStream()); 

新代码:

Document doc=null;

        try
        { 

            String url = getUrl(p, q);
            DocumentBuilderFactory dbfAdd = DocumentBuilderFactory.newInstance();
            DocumentBuilder dbAdd = dbfAdd.newDocumentBuilder();
            doc = dbAdd.parse(url.toString());

最佳答案

IIRC Android 的 XML 文档解析器无法处理阻塞的 InputStream。最好使用为您下载的 parse() 版本,即:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(urlString.toString());

关于android - 无法在 android 中打开来自 google map api 的流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3878695/

相关文章:

可移植联系人 API 的 .NET 实现

android - Android SQLite创建表问题

android - 从 tess-two 库中识别的文本是错误的

android - 棉花糖与 SQLite 绑定(bind)数据花费太多时间

android - AlertDialog 并带有列表项和自定义主题

rest - 什么是 https ://i. instagram.com/api/v1

android - 如何以编程方式删除 FragmentStatePagerAdapter 使用的 Fragment 中不是 LinearLayout 的任何 View ?

java - 良好的性能指标 API?

java - Rhapsody 插件测试

iphone - 不使用 SalesForce Webview 登录 iOS 上的 SalesForce?