I've tried the aproach of reading this URL http://maps.google.com/maps?f=d&hl=en&s ... output=kml in kml format and then extract the info that I want (Example: Distance: 44.7km (about 54mins)).
The problem is that it takes about one second to process one address. So if I've 20 contacts with addresses it will take 20seconds.
Is there another way to accomplish what i'm pretending to doing?
Here is my code:
Using java Syntax Highlighting
- StringBuilder urlString = new StringBuilder();
- urlString.append("http://maps.google.com/maps?f=d&hl=en");
- urlString.append("&saddr=");//my location
- urlString.append(mylocation);
- urlString.append("&daddr=");//contact address
- urlString.append(contactAddress);
- urlString.append("&ie=UTF8&0&om=0&output=kml");
- Document doc = null;
- HttpURLConnection urlConnection= null;
- URL url = new URL(urlString.toString());
- urlConnection=(HttpURLConnection)url.openConnection();
- try {
- urlConnection.setRequestMethod("GET");
- } catch (ProtocolException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- urlConnection.setDoOutput(true);
- urlConnection.setDoInput(true);
- urlConnection.connect();
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- doc = db.parse(urlConnection.getInputStream());
- Element topElement = doc.getDocumentElement();
- NodeList description = topElement.getElementsByTagName("description");
- Element result = (Element) description.item(placemark.getLength()-1);
- String distanceAndTime = route.getFirstChild().getNodeValue();
- String[] splitResult = distanceAndTime.split("<br/>");
- distanceAndTime = splitResult[0].replace(" "," ");
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Thanks in adavance

