Guest User

Untitled

a guest
Feb 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. public class DrawRoute {
  2.  
  3. private WeatherMapActivity listener;
  4. private GoogleMap mMap = WeatherMapActivity.mMap;
  5. private List<Step> stepsInThePath = WeatherMapActivity.stepsInThePath;
  6.  
  7. public DrawRoute(WeatherMapActivity listener) {
  8. this.listener = listener;
  9. Log.d("imHere", "in the DrawRouteConstructor");
  10. }
  11.  
  12. public void execute(){
  13. Log.d("imHere", "in the execute of DrawRoute");
  14. new DrawPolyline().execute();
  15. }
  16.  
  17. private class DrawPolyline extends AsyncTask<Void, Void, Void> {
  18.  
  19. @Override
  20. protected void onPreExecute() {
  21. Log.d("imHere", "in the PreExecute");
  22. }
  23.  
  24. @Override
  25. protected Void doInBackground(Void... voids) {
  26.  
  27. Log.d("imHere", "in the Background");
  28. Geocoder geocoder = new Geocoder(listener, Locale.getDefault());
  29.  
  30. mMap.addPolyline(new PolylineOptions()
  31. .add(stepsInThePath.get(0).startLocation, stepsInThePath.get(0).endLocation)
  32. .width(8)
  33. .color(Color.RED));
  34.  
  35. mMap.addMarker(new MarkerOptions()
  36. .title(MainActivity.sourceAddress)
  37. .icon(BitmapDescriptorFactory.fromResource(R.drawable.start_red))
  38. .position(stepsInThePath.get(0).startLocation));
  39.  
  40. mMap.addMarker(new MarkerOptions()
  41. .title(MainActivity.destinationAddress)
  42. .icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green))
  43. .position(stepsInThePath.get(stepsInThePath.size()-1).endLocation));
  44.  
  45.  
  46. for(int i=1; i < stepsInThePath.size(); i++){
  47. mMap.addPolyline(new PolylineOptions()
  48. .add(stepsInThePath.get(i-1).endLocation, stepsInThePath.get(i).endLocation)
  49. .width(8)
  50. .color(Color.RED));
  51.  
  52. List<Address> addresses = null;
  53. try {
  54. addresses = geocoder.getFromLocation(stepsInThePath.get(i).startLocation.latitude, stepsInThePath.get(i).startLocation.longitude, 1);
  55. } catch (IOException e) {
  56. e.printStackTrace();
  57. }
  58.  
  59. String cityName = addresses.get(0).getLocality();
  60.  
  61. if(i%5 == 0 || i == stepsInThePath.size()-1){
  62. mMap.addMarker(new MarkerOptions()
  63. .title(cityName)
  64. .position(stepsInThePath.get(i).startLocation));
  65. }
  66. }
  67.  
  68. mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(stepsInThePath.get(0).startLocation, 5));
  69.  
  70. return null;
  71. }
  72.  
  73. @Override
  74. protected void onPostExecute(Void aVoid) {
  75. Log.d("imHere", "in the PostExecute");
  76. // progressDialog.dismiss();
  77. }
  78. }
  79. }
Add Comment
Please, Sign In to add comment