In the post, I will compare API from three different providers to search nearby places the three API to compare are: Google Places API, Geoapify API and HERE API.
For each of the platforms, you need to register and get a developer API key to use. All the platform offer a limited free API quota to start with.
Google Places API
import requests
import pandas as pd
from datetime import datetime
df = pd.read_csv('datafile.csv')
YOUR_API_KEY = 'AIza......'
i = 1
for row, col in df.iterrows():
lat = col['Latitude']
long = col['Longitude']
print(i, 'Processing...', lat, long)
url = f'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={lat}%2C{long}&radius=4850&type=laundry&keyword=laundromats&key={YOUR_API_KEY}'
payload={}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
# Get current time...
now = datetime.now()
current_time = now.strftime("%Y%m%d__%H%M%S")
# Write to file....
with open(fr'JSON folder\\GoogleAPI\\{state_folder}\\{current_time}.json', 'w') as outfile:
json.dump(response.json(), outfile)
i = i+1
print('Done...')
Geoapify API
GeoApify_API_KEY = '378122b08....'
url = 'https://api.geoapify.com/v2/places'
params = dict(
categories: 'commercial',
filter: 'rect:7.735282,48.586797,7.756289,48.574457',
limit: 2000,
apiKey=f'{GeoApify_API_KEY}'
)
resp = requests.get(url=url, params=params)
data = resp.json()
print(data)
HERE API
HERE_API_KEY = 'WEYn....'
coord = '27.95034271398129,-82.45670935632066' # lat, long
url = f'https://places.ls.hereapi.com/places/v1/discover/here?apiKey={HERE_API_KEY}&at={coord}&laundry'
response = requests.get(url).json()
# print(response.text)
# Get current time...
now = datetime.now()
current_time = now.strftime("%Y%m%d__%H%M%S")
# Write to file....
with open(fr'JSON folder\\{current_time}.json', 'w') as outfile:
json.dump(response, outfile)
print('Done...')
No comments:
Post a Comment