/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/provider/GoogleStationProvider.java
ViewVC logotype

Contents of /android/TrainInfo/src/dk/thoerup/traininfo/provider/GoogleStationProvider.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1160 - (show annotations) (download)
Mon Oct 4 08:42:12 2010 UTC (13 years, 7 months ago) by torben
File size: 2463 byte(s)
Make cache cleanup code a little more elegant
1 package dk.thoerup.traininfo.provider;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.json.JSONArray;
7 import org.json.JSONObject;
8
9 import android.location.Location;
10 import android.util.Log;
11 import dk.thoerup.android.traininfo.common.StationBean;
12 import dk.thoerup.traininfo.util.DownloadUtil;
13 @Deprecated
14 public class GoogleStationProvider implements StationProvider {
15
16
17
18 public StationBean lookupStationsByName(String name) {
19 return null; // Not supported
20 }
21
22 @Override
23 public StationBean lookupStationsByIds(String ids) {
24 return null;
25 }
26
27 @Override
28 public StationBean lookupStations(Location location) {
29
30 StationBean stations = new StationBean();
31 /*
32 //ToDo: to be nice put the api key into the request
33 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";
34 //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";
35
36 try {
37 String data = DownloadUtil.getContentString(urlSource, 30000);
38 StringBuilder builder = new StringBuilder(data);
39
40 while (builder.charAt(0) != '{')
41 builder.deleteCharAt(0);
42 while (builder.charAt(builder.length()-1) != '}')
43 builder.deleteCharAt(builder.length()-1);
44
45 JSONObject json = new JSONObject(builder.toString());
46 // now have some fun with the results...
47 JSONArray res = json.getJSONArray("results");
48
49 Location tmpLocation = new Location("gps");
50 stations.clear();
51
52 for (int i=0; i<res.length(); i++) {
53 JSONObject jsonStation = res.getJSONObject(i);
54
55 double lat = jsonStation.getDouble("lat");
56 double lng = jsonStation.getDouble("lng");
57 String title = jsonStation.getString("title");
58 String addr = jsonStation.getString("streetAddress");
59 tmpLocation.setLatitude(lat);
60 tmpLocation.setLongitude(lng);
61
62 float distance = location.distanceTo(tmpLocation);
63
64 stations.add( new StationBean(title,lat,lng,(int)distance,addr) );
65
66 Log.e("Location", title + " " + lat +"," + lng);
67 }
68
69 } catch (Exception e) {
70 Log.e("Location","Location",e);
71 return null;
72 }*/
73 return stations;
74 }
75
76 @Override
77 public void purgeOldEntries() {
78 // TODO Auto-generated method stub
79
80 }
81 }

  ViewVC Help
Powered by ViewVC 1.1.20