def post(self): data = self.get_body() geo = geocode(data['address']) pos1 = np.array([geo.lat, geo.lon]) pos2Dictionary = collections.OrderedDict() for user in User.query().fetch(): user_geo = geocode(user.full_address()) if (user_geo != None): pos2Dictionary[user.key.id()] = [user_geo.lat, user_geo.lon] dists = distance.get_distance_sorted_responders(pos1, pos2Dictionary) user = User.get_by_id(dists.keys()[0]) return JsonResponse(user)
def findLat(addr): # Function to find latitude and longitude using google maps API gmaps = Client(key='AIzaSyAr6MafwMH3Anrx_aJNb3_y7KrWKlCcNOA') geocode_result = gmaps.geocode(addr) lat = geocode_result[0]["geometry"]["location"]["lat"] lon = geocode_result[0]["geometry"]["location"]["lng"] return [lat, lon]
def Geocode(query): # do geocoding try: geocode_result = gm.geocode(query)[0] latitude = geocode_result['geometry']['location']['lat'] longitude = geocode_result['geometry']['location']['lng'] return latitude, longitude except IndexError: return 0
def geo(address): gmaps = googlemaps.Client(key="AIzaSyB1Udy3X-6-BGZaJt-SIT0OrvUWo_i4uWs") results = gmaps.geocode(address) for result in results: geo = result['geometry'] lat, lng = geo['location']['lat'], geo['location']['lng'] metrics = ("{lat: %s, lng: %s}" % (lat, lng)) return (metrics)
def save(self, force_insert=False, force_update=False): self.city = self.city.capitalize() # update geocoding infos try: loc = gmaps.geocode(self.__unicode__()) except Exception: return False self.lat = loc['lat'] self.long = loc['lng'] super(Address, self).save(force_insert, force_update)
def findPos(pollStations, data): gmaps = googlemaps.Client(key='AIzaSyA-Mb5xxYe0XkHkkoEMl_YqbRjCcnwQjRY') positions = pd.DataFrame(columns=['lat', 'lon'], index=pollStations) for i in pollStations: geocode_result = gmaps.geocode(i) positions.loc[i]['lat'] = geocode_result[0]["geometry"]["location"][ "lat"] positions.loc[i]['lon'] = geocode_result[0]["geometry"]["location"][ "lng"] return positions
print(i, result) if isSuccess == True: # if geocoding is successful, # store the results lat.append(result[0]) # latitude lng.append(result[1]) # longitude return lat, lng # call the geocoding function [lat, lng] = GeocodeStreetLocationCity(data) # we put the list of latitude,longitude into pandas data frame df = pd.DataFrame({'latitude': lat, 'longitude': lng}) # do geocode for the whole mega city geocode_result = gm.geocode('Metro Manila')[ 0] # change the name into your city of interest # get the center of the city center_lat = geocode_result['geometry']['location']['lat'] center_lng = geocode_result['geometry']['location']['lng'] print('center=', center_lat, center_lng) # get the bounding box of the city i.e. Metro Manila bounding_box = geocode_result['geometry']['bounds'] lat_boundary = [ bounding_box['southwest']['lat'], bounding_box['northeast']['lat'] ] lng_boundary = [ bounding_box['southwest']['lng'], bounding_box['northeast']['lng'] ] print('boundary:', lat_boundary, lng_boundary)
plt.show() # Maps integration api_key = payload['api_key'] gmaps = googlemaps.Client(key=api_key) # Geocoding a city # geocode_result = gmaps.geocode(all_cities[0]) latitudes = list() longitudes = list() # loop over all cities and get the geocoding --> also for duplicates for density on heatmap for city in all_cities: try: geocode_result = gmaps.geocode(city) lngDif = ( geocode_result[0]['geometry']['bounds']['southwest']['lng'] - geocode_result[0]['geometry']['bounds']['northeast']['lng']) / 2 latDif = ( geocode_result[0]['geometry']['bounds']['southwest']['lat'] - geocode_result[0]['geometry']['bounds']['northeast']['lat']) / 2 lat = geocode_result[0]['geometry']['bounds']['northeast'][ 'lat'] + latDif lng = geocode_result[0]['geometry']['bounds']['northeast'][ 'lng'] + lngDif latitudes.append(lat) longitudes.append(lng)