163 |
intent.putExtra("latitude", latitude); |
intent.putExtra("latitude", latitude); |
164 |
intent.putExtra("longitude", longitude); |
intent.putExtra("longitude", longitude); |
165 |
intent.putExtra("stationid", station.getId()); |
intent.putExtra("stationid", station.getId()); |
166 |
|
intent.putExtra("address", station.getAddress()); |
167 |
startActivity(intent); |
startActivity(intent); |
168 |
} |
} |
169 |
|
|
170 |
|
String lookupAddress(double latitude, double longitude) { |
171 |
|
|
172 |
|
Geocoder coder = new Geocoder(this, new Locale("da")); |
173 |
|
StringBuilder sb = new StringBuilder(); |
174 |
|
Log.i("lookupaddr", "" + latitude + "/" + longitude); |
175 |
|
try { |
176 |
|
List<Address> addressList = coder.getFromLocation(latitude, longitude, 1); |
177 |
|
Address addr = addressList.get(0); |
178 |
|
|
179 |
|
|
180 |
|
int max = addr.getMaxAddressLineIndex(); |
181 |
|
for (int i=0; i<max; i++) { |
182 |
|
if (i>0) |
183 |
|
sb.append(", "); |
184 |
|
|
185 |
|
sb.append(addr.getAddressLine(i)); |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
} catch (Exception e) { |
190 |
|
Log.e("DepartureList", "geocoder failed", e); |
191 |
|
} |
192 |
|
|
193 |
|
return sb.toString(); |
194 |
|
} |
195 |
|
|
196 |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
197 |
@Override |
@Override |
204 |
protected Void doInBackground(Void... params) { |
protected Void doInBackground(Void... params) { |
205 |
locator.findNearestStations(); |
locator.findNearestStations(); |
206 |
|
|
207 |
|
List<StationBean> stations = locator.getStations(); |
208 |
|
for (StationBean station : stations) { |
209 |
|
String addr = lookupAddress(station.getLatitude(), station.getLongitude()); |
210 |
|
station.setAddress(addr); |
211 |
|
} |
212 |
|
|
213 |
return null; |
return null; |
214 |
} |
} |
215 |
|
|