Google Maps | Duration (Android Tutorials)
Find me here : Hello everyone, In this tutorial, I am explaining how you can calculate the distance between your current location and your destination. I have implemented the class by 2 more classes which are GoogleMap.OnMarkerClickListener and GoogleMap.OnMarkerDragListener. So, when you click on the marker it will become draggable and then you can drag it to any location on the map that you want to set as destination. I have added a separate button to calculate the distance. So after setting the destination, I am storing the latitude and longitude values of the destination using onMarkerDragEnd method in 2 class variables so they will be accessible throughout the class. In the previous tutorial, I created a separate case in the onClick method for the new button. When the user click on the button, we are calling Location class's distanceBetween() method which takes 5 parameters - start latitude, start longitude, end latitude, end longitude and array to store the results. It's return type is void. So, I created a float array to store the results and then passed all the parameters in that method and then it returned the distance between current location and the destination in meters. You can drag the marker to a new location after this and again click on the to button and it will again calculate the distance between your current location and the new destination. In this tutorial, I am displaying the duration and the distance using Directions API. Thank you. Find me here : Google+ : https://plus.google.com/u/0/b/105970252005982916681/105970252005982916681/posts Twitter : https://twitter.com/AndroidAcademy1 Facebook : https://www.facebook.com/AndroidAcademy8?ref=hl
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.