package dk.thoerup.traininfo.provider; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; import android.location.Location; import android.util.Log; import dk.thoerup.traininfo.StationBean; import dk.thoerup.traininfo.util.DownloadUtil; public class GoogleStationProvider implements StationProvider { List stations = new ArrayList(); public boolean lookupStationsByName(String name) { return false; // Not supported } @Override public boolean lookupStationsByIds(String ids) { return false; } @Override public boolean lookupStations(Location location) { boolean success = false; //ToDo: to be nice put the api key into the request String urlSource = "http://www.google.com/uds/GlocalSearch?callback=google.search.LocalSearch.RawCompletion&context=1&q=Train%20station&near=" + location.getLatitude() + "%2C" + location.getLongitude() + "&v=1.0"; //String urlSource = "http://www.google.com/uds/GlocalSearch?callback=google.search.LocalSearch.RawCompletion&context=1&q=Train%20station&near=56.2%2C9.0&v=1.0"; try { String data = DownloadUtil.getContentString(urlSource, 30000); StringBuilder builder = new StringBuilder(data); while (builder.charAt(0) != '{') builder.deleteCharAt(0); while (builder.charAt(builder.length()-1) != '}') builder.deleteCharAt(builder.length()-1); JSONObject json = new JSONObject(builder.toString()); // now have some fun with the results... JSONArray res = json.getJSONArray("results"); Location tmpLocation = new Location("gps"); stations.clear(); for (int i=0; i getStations() { return stations; } }