开发者

Unable to open the stream coming from google map api in android?

开发者 https://www.devze.com 2023-01-19 04:52 出处:网络
When i am using below url for drawing route on map on android: StringBuilder urlString = new StringBuilder();

When i am using below url for drawing route on map on android:

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

Its throwing exception when urlConnection.getInputStream is called.

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.getInputSt开发者_运维知识库ream()); 

New Code:

Document doc=null;

        try
        { 

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


IIRC Android's XML document parser cannot handle an InputStream which blocks. Better to use the version of parse() which does the download for you, i.e. :

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

精彩评论

暂无评论...
验证码 换一张
取 消