Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawRoute {
- private WeatherMapActivity listener;
- private GoogleMap mMap = WeatherMapActivity.mMap;
- private List<Step> stepsInThePath = WeatherMapActivity.stepsInThePath;
- public DrawRoute(WeatherMapActivity listener) {
- this.listener = listener;
- Log.d("imHere", "in the DrawRouteConstructor");
- }
- public void execute(){
- Log.d("imHere", "in the execute of DrawRoute");
- new DrawPolyline().execute();
- }
- private class DrawPolyline extends AsyncTask<Void, Void, Void> {
- @Override
- protected void onPreExecute() {
- Log.d("imHere", "in the PreExecute");
- }
- @Override
- protected Void doInBackground(Void... voids) {
- Log.d("imHere", "in the Background");
- Geocoder geocoder = new Geocoder(listener, Locale.getDefault());
- mMap.addPolyline(new PolylineOptions()
- .add(stepsInThePath.get(0).startLocation, stepsInThePath.get(0).endLocation)
- .width(8)
- .color(Color.RED));
- mMap.addMarker(new MarkerOptions()
- .title(MainActivity.sourceAddress)
- .icon(BitmapDescriptorFactory.fromResource(R.drawable.start_red))
- .position(stepsInThePath.get(0).startLocation));
- mMap.addMarker(new MarkerOptions()
- .title(MainActivity.destinationAddress)
- .icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green))
- .position(stepsInThePath.get(stepsInThePath.size()-1).endLocation));
- for(int i=1; i < stepsInThePath.size(); i++){
- mMap.addPolyline(new PolylineOptions()
- .add(stepsInThePath.get(i-1).endLocation, stepsInThePath.get(i).endLocation)
- .width(8)
- .color(Color.RED));
- List<Address> addresses = null;
- try {
- addresses = geocoder.getFromLocation(stepsInThePath.get(i).startLocation.latitude, stepsInThePath.get(i).startLocation.longitude, 1);
- } catch (IOException e) {
- e.printStackTrace();
- }
- String cityName = addresses.get(0).getLocality();
- if(i%5 == 0 || i == stepsInThePath.size()-1){
- mMap.addMarker(new MarkerOptions()
- .title(cityName)
- .position(stepsInThePath.get(i).startLocation));
- }
- }
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(stepsInThePath.get(0).startLocation, 5));
- return null;
- }
- @Override
- protected void onPostExecute(Void aVoid) {
- Log.d("imHere", "in the PostExecute");
- // progressDialog.dismiss();
- }
- }
- }
Add Comment
Please, Sign In to add comment