开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜