Possible Duplicate:
getContentLength() returning -1 on some devices and not others
I’m doing on an Android app that will show the the route from a place to another place.
So firstly I need to get the kml file and then parse in. However, my parse size is -1 which is not suppose to be so. The parse size must be bigger than -1 but I couldn’t get it. Can anyone help me out? Thank you!
// connect to map web service
StringBuilder urlString = new StringBuilder();
urlString.append("http://maps.google.com/maps?f=d&hl=en");
urlString.append("&saddr=");//from
urlString.append( Double.toString((double)src.getLatitudeE6()/1.0E6 ));
urlString.append(",");
urlString.append( Double.toString((double)src.getLongitudeE6()/1.0E6 ));
urlString.append("&daddr=");//to
urlString.append( Double.toString((double)dest.getLatitudeE6()/1.0E6 ));
urlString.append(",");
urlString.append( Double.toString((double)dest.getLongitudeE6()/1.0E6 ));
urlString.append("&ie=UTF8&0&om=0&output=kml");
Log.d("DrawPath","URL="+urlString.toString());
// get the kml (XML) doc. And parse it to get the coordinates(direction route).
Document doc = null;
HttpURLConnection urlConnection= null;
URL url = null;
try
{
url = new URL(urlString.toString());
urlConnection=(HttpURLConnection)url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Log.d("Before parse", "size:" + urlConnection.getContentLength());
doc = db.parse(urlConnection.getInputStream());
You need to pass the correct latitude and longitude values for this. I could do this with your code. I tried passing Longitude and latitude values corrected up to 7 decimal points. I tried this.
Try with following.
Pune = > srcLat = 18.4577015;
Pune = > srcLong = 73.8552158;
Mumbai = > destLat = 19.017576;
Mumbai = > destLong = 72.8562427;
Result: Before parse size:47555