Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate distance using google map given a latitude and longitude

I am developing a desktop application and I have two point (latitude, longitude). How can I get the distance between these two points? I have looked at the API and most of them are javascript or web based. I am not developing a web page. How can I do this in java?

I want a road distance, not a straight distance

like image 320
aherlambang Avatar asked Sep 19 '25 10:09

aherlambang


1 Answers

If you've got the latitude and longitude, you can use the Haversine formula to calculate the distance between them - assuming you want "straight line" distance.

EDIT: Okay, now you've actually told us what you want, I suspect you need to use the Directions API. You'll need to make a web request to the appropriate URL with your parameters, specifying either XML or JSON output - which you'll then need to parse.

Note that "JSON" != "Javascript-based". Think of JSON as a data serialization format which just happens to be executable Javascript.

like image 61
Jon Skeet Avatar answered Sep 22 '25 00:09

Jon Skeet