开发者

How can I calculate distance and bearing using latitude and longitude?

Assume these 4 values:

        double lat1 = ToRadians(53.14722222222222);
        double lon1 = ToRadians(-1.8494444444444447);
        double lat2 = ToRadians(52.20444444444445);
        double lon2 = ToRadians(-0.14055555555555554);

I calculate in 开发者_Go百科Google map get direction, I got about 181 km, but in this website (http://www.movable-type.co.uk/scripts/latlong.html) it got about 170 km.

In my source, I use java and c# to implement this function, when I calculate it, I got about 155 km.

why they are not equivalent?

Do you have any function that can calculate this 2 values accurately?


The Haversine formula on the web site is reasonable accurate "as the crow flies." You don't say how you used Google maps to calculate the distance, but if you simply put in the values and asked it to calculate a route, it would be using the driving distance (following roads) which would be longer. If your implementation of the Haversine formula comes up with a different answer than the web site, then either you or they have implemented it incorrectly. You might find another web site to check your answer against to see which.

You can find an implementation in C# here.


On Google Earth the value is 155.92km. So it agrees with your result.

Google Earth uses a Great Circle Distance calculation, that takes into account the fact that the Earth is a Sphere. I don't know about the other two sources though.

I would keep your current implementation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜