def get_location_coord(lat, lon, loc, app_id, app_code): ''' Get address and position information by coordinates or location, app_id and app_code are generate when you sing up in here.com in freemium version. If latitude coordinate is null, get information by location data. ''' geocoderApi = herepy.GeocoderApi(app_id, app_code) geocoderReverseApi = herepy.GeocoderReverseApi(app_id, app_code) address = None position = None if lat is None or np.isnan(lat): response = geocoderApi.free_form(loc) if response.as_dict()['Response']['View']: address = response.as_dict( )['Response']['View'][0]['Result'][0]['Location']['Address'] position = response.as_dict()['Response']['View'][0]['Result'][0][ 'Location']['DisplayPosition'] else: response = geocoderReverseApi.retrieve_addresses([lat, lon]) if response.as_dict()['Response']['View']: address = response.as_dict( )['Response']['View'][0]['Result'][0]['Location']['Address'] position = response.as_dict()['Response']['View'][0]['Result'][0][ 'Location']['DisplayPosition'] else: response = geocoderApi.free_form(loc) if response.as_dict()['Response']['View']: address = response.as_dict( )['Response']['View'][0]['Result'][0]['Location']['Address'] position = response.as_dict()['Response']['View'][0]['Result'][ 0]['Location']['DisplayPosition'] return address, position
def handler(event, context): """ Handler for the Lambda function. Gets the coordinates as input from the AWS AppSync API, then gets the address information using the Geocoder Reverse HERE API. """ print('request: {}'.format(json.dumps(event))) latitude = float(event['arguments']['coordinates']['latitude']) longitude = float(event['arguments']['coordinates']['longitude']) here_api_key = os.environ['HERE_API_KEY'] geocoder_reverse_api = herepy.GeocoderReverseApi(here_api_key) response_here = geocoder_reverse_api.retrieve_addresses( [latitude, longitude]) response_location = response_here.items[0] response_address = response_location['address'] response_location = response_location['position'] address = { 'street': response_address['label'], 'city': response_address['city'], 'state': response_address['state'], 'country': response_address['countryCode'], 'latitude': response_location['lat'], 'longitude': response_location['lng'] } print('response: {}'.format(json.dumps(address))) return address
def getLocationDetails(latitude, longitude): latitude = float(latitude) longitude = float(longitude) # api = "AIzaSyCOkw95Uhnr5QLxP0A0sDbtGr-aI4MHeSo" # url = "https://maps.googleapis.com/maps/api/geocode/json?latlng={},{}&key={}".format(latitude,longitude,api) # print(url) # response = requests.get(url) # response = json.loads(response.text) # print(response['results']) # response = response['results'][0]['address_components'][1]['long_name'] #url = "https://us1.locationiq.com/v1/reverse.php?key=ba6d9d5b67664b&lat={}&lon={}&format=json".format(latitude,longitude) #print(url) #response = requests.get(url) #response = json.loads(response.text) #response = response['address']['road'] gp = herepy.GeocoderReverseApi('wWRTCQ8UwCm4mELqVFKh', 'YyS1iuR4G9SZ8vkUmDGrXg') response = gp.retrieve_addresses([latitude, longitude]) response = str(response) response = ast.literal_eval(response) response = response["Response"]["View"][0]["Result"][0]["Location"][ "Address"]["Label"] return response
def reverse_geocoder_here(coords, token=HERE_API_KEY): """ coords: (lat, lng) ==> 4 Av du General de Gaulle """ geocoderReverseApi = herepy.GeocoderReverseApi(token) res = geocoderReverseApi.retrieve_addresses(coords) res = res.as_dict() adress = res["Response"]["View"][0]["Result"][0]["Location"]["Address"] return adress
def reverse_geocoder_here(coords, token=HERE_API_KEY): """ coords: (lat, lng) ==> 4 Av du General de Gaulle """ geocoderReverseApi = herepy.GeocoderReverseApi(token) res = geocoderReverseApi.retrieve_addresses(coords) res = res.as_dict() adress = res['items'][0]['address']['label'] return adress
def __init__(self): self.modes = {'walk':[herepy.RouteMode.pedestrian,herepy.RouteMode.shortest],'bus':[herepy.RouteMode.publicTransport,herepy.RouteMode.fastest],'car':[herepy.RouteMode.car,herepy.RouteMode.fastest,herepy.RouteMode.traffic_enabled]} self.api_key = self.getconfig("maps_api")#"NuWLrM7oE23-PKjQWHD79izu0aFFvYdEu7wZV0SanSE" self.max_radius = self.getconfig("maxradius")*1000 #Enter in KM self.geocoderApi = herepy.GeocoderApi(self.api_key) self.geocoderAutoCompleteApi = herepy.GeocoderAutoCompleteApi(self.api_key) self.routingApi = herepy.RoutingApi(self.api_key) self.geocoderReverseApi = herepy.GeocoderReverseApi(self.api_key) self.placesApi = herepy.PlacesApi(self.api_key) self.current_coordinates = [0,0] self.loadconfig()
def reverse_geocoder_here(coords, token=HERE_API_KEY): """ coords: (41.79, -74.74) ==> 36 Liberty Commons Way, Liberty, NY 12754-3009, United States """ geocoderReverseApi = herepy.GeocoderReverseApi(token) res = geocoderReverseApi.retrieve_addresses(coords) res = res.as_dict() adress = res['items'][0]['address']['label'] lat = res['items'][0]['position']['lat'] lng = res['items'][0]['position']['lng'] return {"adress": adress, "lat": lat, "lng": lng}
def get_phone_number(): loc = worker() geocoderApi = herepy.GeocoderApi('rTc2ExgvmtXRk5fJG3IB', 'HwAH1Q70PPoaHB-hqswuHQ') geocoderReverseApi = herepy.GeocoderReverseApi('rTc2ExgvmtXRk5fJG3IB', 'HwAH1Q70PPoaHB-hqswuHQ') response = requests.get('https://places.cit.api.here.com/places/v1/autosuggest?at=37.787541999999995,-122.4109585&q=police&station&app_id=rTc2ExgvmtXRk5fJG3IB&app_code=HwAH1Q70PPoaHB-hqswuHQ') parsed = json.loads(response.text) url = parsed['results'][0]['href'] response2 = requests.get(url) parsed2 = json.loads(response2.text) station_url = parsed2['results']['items'][0]['href'] response3 = requests.get(station_url) parsed3 = json.loads(response3.text) phoneNumber = parsed3['contacts']['phone'][0]['value'] print(phoneNumber)
def setUp(self): api = herepy.GeocoderReverseApi("api_key") self._api = api
#!/usr/bin/env python # coding: utf-8 # In[5]: import herepy import json import requests geocoderApi = herepy.GeocoderApi('rTc2ExgvmtXRk5fJG3IB', 'HwAH1Q70PPoaHB-hqswuHQ') geocoderReverseApi = herepy.GeocoderReverseApi('rTc2ExgvmtXRk5fJG3IB', 'HwAH1Q70PPoaHB-hqswuHQ') from locations import location_data loc = location_data() # In[6]: response = requests.get('https://places.cit.api.here.com/places/v1/autosuggest?at='+loc+'&q=police&station&app_id=rTc2ExgvmtXRk5fJG3IB&app_code=HwAH1Q70PPoaHB-hqswuHQ') parsed = json.loads(response.text) url = parsed['results'][0]['href'] response2 = requests.get(url) parsed2 = json.loads(response2.text) station_url = parsed2['results']['items'][0]['href']
import herepy geocoderReverseApi = herepy.GeocoderReverseApi('zBS9SRvVcsFK8749nYuo', 'kGOV-ygj7_lbXN9df8o5Uw') #geoc=[11.061960,77.037069] def loc(geoc): response = geocoderReverseApi.retrieve_addresses(geoc) #print(response) reply=response.as_dict() label=reply["Response"]["View"][0]['Result'][0]['Location']['Address']['Label'] #print(label) return str(label) #x=loc([11.061960,77.037069]) #print(x,type(x))
def setUp(self): api = herepy.GeocoderReverseApi('app_id', 'app_code') self._api = api