API purpose: GPS Distance
Signup: Using the google developer portal
Documentation: https://developers.google.com/maps/web-services/client-library
Github: https://github.com/gregario/API-Month/tree/master/Day6%20GPS%20Distance
Comment: Continuation of day 4, interesting problem.
Quick one today after yesterday drove me mad. Wanted to do a quick function that takes in two sets of GPS data and works out the distance between them. I did some reading on calculating distances between two points on a map. Apparently its a real issue in the mapping community with many implementations of map hashing being discussed.
My first thoughts would be to take the two latitudes from each other, take the absolute of that. Then do the same with longditude and then add those two numbers together. In math-y terms it would be:
distance = abs(lat2 - lat1) + abs(long2 - long2)
But then I had a flashback to my school maths and it would be more appropriate to do a pythagoras job on it. Basically take the two points as a hypotenuse of a right angled triangle. Then I had the fun of programming it in python, I got:
math.sqrt((p0[0] - p1[0])**2 + (p0[1] - p1[1])**2)
A small aside but another thing I did for today was to make an API key file that I can use with all my programs. So commiting your API keys to Git is generally a bad thing. People have scripts running to search for API key, particularly for anything to do with AWS, and start hammering them once they’re found. It can end up costing a bunch of money. So I have a separate file I do not commit to any Git repository and I add to my files by importing it like any other module in python. It also is a nice system for configuration files if you want to make your python scripts more abstract.
So new code, here it it.
|
|