开发者

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 developi开发者_开发知识库ng a web page. How can I do this in java?

I want a road distance, not a straight distance


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.


A quick Google gave me this: http://www.postalcodeworld.com/samples/distance.java.html Looks like this is a pretty good implementation of what you need using the Haversine Formula I think.


This Great Circle Distance code above is probaby OK for most apps. If you need great deal of precision, though, be aware that it may fail in some edge cases due to the earth not being a perfect sphere. In that case you're talking about more complicated algorithms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜