I try to get the distance between two points by showing them together with a polyline. One marker is permanently somewhere and the other the user chooses the place they want when clicking on the map. I tried with many codes obtained from the Internet but for me neither works or just gives me the marker of a place with the latutude and longitude. I want to use retrofit 2 to bring the information. Can anyone help me with that?
Asked
Active
Viewed 828 times
1 Answers
1
On clicking on map you are placing marker, So if you want to get location of that marker then simply you can got that marker position using that marker object like this.
Double latitude = marker.getPosition().latitude;
Double longitude = marker.getPosition.longitude;
and you have already one location so you can find distance between two locations using this.
locationFrom.distanceTo(locationDestination);
here locationFrom is your source location from where you want to find distance and locationDestination is your destination location to where you find distance.

Nilam Vaddoriya
- 433
- 2
- 10
-
Is good to know but I want to calculate the distance between the two markers like if you want to go from the first marker to the second marker with the car, using the road. that is because I need to multiply the distance that some one need to travel by car with a constant number to have an especific result. – juan Aug 03 '17 at 14:34
-
. – juan Aug 03 '17 at 14:57
-
I saw it with locationFrom.distanceTo (locationDestination); It works, but it is not too accurate with the result when compared to google maps on the computer. So how do I get that data as if I use the road? – juan Aug 03 '17 at 20:03
-
Are you talking about something like live tracking? – Nilam Vaddoriya Aug 04 '17 at 09:38
-
No exactly! I want to know how to get the distance between two markers. I know that your metod works but it measure the distance in rect line. I want to measure the distance like when you go to google maps from computer and you select two places to show the routes that you can take with the car. I saw that the information that I need can be taken from here [JSON google](https://maps.googleapis.com/maps/api/distancematrix/json?origins=9.993440,-83.027811&destinations=8.600642,%20-83.115977&mode=driving) But I dont know how to bring that information using retrofit or the other methots – juan Aug 04 '17 at 14:25
-
Also it is posible to bring the name of the origin and the destination? – juan Aug 04 '17 at 14:27