try { // build the URL using the latitude & longitude you want to lookup // NOTE: I chose XML return format here but you can choose something // else serverAddress = new URL("http://maps.google.com/maps/geo?q=" + Double.toString(loc.getLatitude()) + "," + Double.toString(loc.getLongitude()) + "&output=xml&oe=utf8&sensor=true&key=" + GOOGLE_MAPS_API_KEY); // set up out communications stuff connection = null;
// Set up the initial connection connection = (HttpURLConnection) serverAddress.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setReadTimeout(10000);
connection.connect();
try { InputStreamReader isr = new InputStreamReader(connection .getInputStream()); InputSource source = new InputSource(isr); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader xr = parser.getXMLReader(); GoogleReverseGeocodeXmlHandler handler = new GoogleReverseGeocodeXmlHandler();