--- android/TrainInfo/src/dk/thoerup/traininfo/StationLocator.java 2009/08/10 10:49:43 252 +++ android/TrainInfo/src/dk/thoerup/traininfo/StationLocator.java 2009/08/10 16:58:22 253 @@ -15,6 +15,8 @@ import android.os.Bundle; import android.os.Handler; import android.util.Log; +import dk.thoerup.traininfo.provider.ProviderFactory; +import dk.thoerup.traininfo.provider.StationProvider; import dk.thoerup.traininfo.util.DownloadUtil; public class StationLocator implements LocationListener{ @@ -23,8 +25,7 @@ Context cntx; Handler hndl; - ArrayList stationList = new ArrayList(); - List safeStationList = java.util.Collections.unmodifiableList(stationList); + List stationList = new ArrayList(); Location savedLocation = null; @@ -35,7 +36,7 @@ } public List getStations() { - return safeStationList; + return stationList; } public void abortLocationListener() { @@ -88,49 +89,14 @@ } public void findNearestStations(Location location) { - //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.getContent(urlSource, 30000, "UTF-8"); - 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"); - stationList.clear(); - - for (int i=0; i 0) hndl.sendEmptyMessage(TrainInfoList.GOTSTATIONLIST); - - } catch (Exception e) { - Log.e("Location","Location",e); + else hndl.sendEmptyMessage(TrainInfoList.LOOKUPSTATIONFAILED); - } - } @@ -153,6 +119,7 @@ // TODO Auto-generated method stub } + public static void injectMockLocation(Context cntx) { Location odder = new Location("gps2"); @@ -163,6 +130,11 @@ kbh.setLatitude(55.675092); kbh.setLongitude(12.578573); + Location bjbro = new Location("gps2"); + bjbro.setLatitude(56.380745); + bjbro.setLongitude(9.655609); + + LocationManager lm = (LocationManager) cntx.getSystemService(Context.LOCATION_SERVICE); if (lm.getProvider("gps2") == null) lm.addTestProvider("gps2", false, true, true, false, false, false, false, 0, Criteria.ACCURACY_FINE );