Created
September 14, 2017 06:08
-
-
Save giwiro/68a80d0f35261acf246b4e99fc33e2fb to your computer and use it in GitHub Desktop.
Python3 program to find near places to eat between 2 points using google maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from googlemaps import Client | |
from pprint import pprint | |
KEY = "xxxxxxxxxxxxxxxxxxxxxx" | |
FIRST_POINT = (-12.0923872,-77.0584926) | |
SECOND_POINT = (-12.09836024,-77.025732065) | |
# meters | |
RADIUS = 500 | |
def calc_mid_point(f, s): | |
return ((f[0] + s[0])/2.0, (f[1] + s[1])/2.0) | |
def execute(): | |
mid = calc_mid_point(FIRST_POINT, SECOND_POINT) | |
gmaps = Client(key=KEY) | |
results = gmaps.places("restaurantes", mid, RADIUS)["results"] | |
print(f"Results for mid point: {mid}") | |
for i, p in enumerate(results): | |
location = p["geometry"]["location"] | |
coord = (location["lat"], location["lng"]) | |
print("-----------------------------------------------------") | |
print(f"{i}:\t{p['name']}") | |
print(f"\t{p['formatted_address']}") | |
print(f"\t{coord}") | |
if __name__ == "__main__": | |
execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment