I've managed to get two functions working to calculate distances between two point on a google map. One that I gleaned(stole) from various places on the web and the other using the GLatLng.distanceFrom method in the Google Maps API.
The reason I'm using two functions is because I noticed something odd about the results I was getting form Google, for example, the distance between Lands End and John O Groats in the UK is returned as follows
The 15/16km difference from the Wikipedia result is because Google return a location result about 15 km away from the actual John O Groats. So that's about right.
So then I tested the distance between London and Milan and got
So someone is more than 250km out. Then I tried London to New York
Generally, the distance between London and New York is thought to be around 5560km. But now both my function and the Google function appear to be way off the mark.
The function I'm using can be found here. My Apologies to the author for not linking to the original site, but the layout is really confusing. I'm using the distHaversine function.
I must admit, the maths is way beyond my comfort level, but I get the gist, and as I understand it, Google uses the Haversine method too. I also understand that it can be off by about 0.3%, but that wouldn't account for the differences I'm seeing. And I'm further confused by the fact that it's sometimes right on, and sometimes way off the commonly stated distances between places. It appears the greater the distance, the more off it is.
So who's wrong. Google and the function I'm using, or everyone else?
Google has all that is required to calculate a distance to 100% accuracy. You have a Map to a scale that is 100% accuracy,presumably. You have a user defined route with waymarks and more than enough computing power to calculate the distances between the waymarks to 100% accuracy based on the scale you have.
GPS: Maps uses satellites to know your location up to around 20 meters. When you're inside buildings or underground, the GPS is sometimes inaccurate. Wi-Fi: The location of nearby Wi-Fi networks helps Maps know where you are. Cell tower: Your connection to mobile data can be accurate up to a few thousand meters.
Google Maps doesn't calculate the shortest straight distance -- it goes by roads and (air, water, ?)
As it turns out, I had the latitude and longitude parameters the wrong way around.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With