44 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
45 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
46 |
|
|
47 |
//StationLocator.removeMockLocation(this); |
StationLocator.removeMockLocation(this); |
48 |
StationLocator.injectMockLocation(this); |
//StationLocator.injectMockLocation(this); |
49 |
|
|
50 |
adapter = new StationListAdapter(this); |
adapter = new StationListAdapter(this); |
51 |
setListAdapter(adapter); |
setListAdapter(adapter); |
154 |
|
|
155 |
double latitude = station.getLatitude(); |
double latitude = station.getLatitude(); |
156 |
double longitude = station.getLongitude(); |
double longitude = station.getLongitude(); |
|
String addr = station.getAddress(); |
|
157 |
|
|
|
if (addr == null || addr.trim().equals("") ) |
|
|
addr = lookupAddress(latitude, longitude); |
|
158 |
|
|
159 |
|
|
160 |
Intent intent = new Intent(this, DepartureList.class); |
Intent intent = new Intent(this, DepartureList.class); |
161 |
intent.putExtra("name", station.getName()); |
intent.putExtra("name", station.getName()); |
|
intent.putExtra("address", addr); |
|
162 |
intent.putExtra("distance", station.getDistance()); |
intent.putExtra("distance", station.getDistance()); |
163 |
intent.putExtra("latitude", latitude); |
intent.putExtra("latitude", latitude); |
164 |
intent.putExtra("longitude", longitude); |
intent.putExtra("longitude", longitude); |
166 |
startActivity(intent); |
startActivity(intent); |
167 |
} |
} |
168 |
|
|
|
String lookupAddress(double latitude, double longitude) { |
|
|
|
|
|
Geocoder coder = new Geocoder(this, new Locale("da")); |
|
|
StringBuilder sb = new StringBuilder(); |
|
|
Log.i("lookupaddr", "" + latitude + "/" + longitude); |
|
|
try { |
|
|
List<Address> addressList = coder.getFromLocation(latitude, longitude, 1); |
|
|
Address addr = addressList.get(0); |
|
|
|
|
|
|
|
|
int max = addr.getMaxAddressLineIndex(); |
|
|
for (int i=0; i<max; i++) { |
|
|
if (i>0) |
|
|
sb.append(", "); |
|
|
|
|
|
sb.append(addr.getAddressLine(i)); |
|
|
} |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
Log.e("DepartureList", "geocoder failed", e); |
|
|
} |
|
|
|
|
|
return sb.toString(); |
|
|
} |
|
169 |
|
|
170 |
|
|
171 |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
class LocatorTask extends AsyncTask<Void,Void,Void> { |