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());
精彩评论