def get_location_info(filename): exif = get_exif(filename) if exif: geotags = get_geotagging(exif) if geotags: coords = get_coordinates(geotags) if coords: geocoder = Here(apikey=HERE_APIKEY) return geocoder.reverse("%s,%s" % coords)
def geocoding(ctx, query, apikey, forward, raw, display): """ HERE's geocoding service. \f :param ctx: A context dictionary. :param query: A string to represent address query for geocoding. :param apikey: An API key for authentication. :param forward: A boolean flag for forward/reverse geocoding. :param raw: A boolean flag to show api response as it is. :param display: A boolean flag to show result in web browser. :return: None. """ apikey = apikey or os.environ.get("HERE_APIKEY") if apikey is None: raise ApiKeyNotFoundError( "Please pass HERE API KEY as --apikey or set it as environment " "variable in HERE_APIKEY " ) ctx.obj["apikey"] = apikey geolocator = Here(apikey=ctx.obj["apikey"]) if forward: location = geolocator.geocode(query) if raw: click.secho(json.dumps(location.raw, indent=2), fg="green") elif display: feature = get_feature_from_lat_lon(location.latitude, location.longitude) geo_display(feature) else: result = {"lat": location.latitude, "lon": location.longitude} click.secho(json.dumps(result, indent=2), fg="green") else: location = geolocator.reverse(query) if raw: click.secho(json.dumps(location.raw, indent=2), fg="green") else: click.secho(location.address, fg="green")
def georeverse(): result = request.get_json(force=True) data = {} try: data['coordinate'] = result['coordinate'] except AttributeError: response = {} response["status"] = False response["message"] = "coordinate is required" response["request"] = result return json.dumps(response) if (not validate_lat_lon(data['coordinate'])): response = {} response["status"] = False response["message"] = "coordinate format is invalid" response["request"] = result return json.dumps(response) t = "" geolocator = Here(app_id="brUMhDedQJcTEBv3WRm2", app_code="gEuqige5xqyAJ3Gi5x1Qaw") #geolocator = Here("Pe8yMxfGgxyn9yWsRDU9","OrUmfFZvhbc2KNVLpvffrw") #old auth glocation = geolocator.reverse(query=data["coordinate"]) #check if lat lon is available, else move it to the antartic zone :) try: glocation.address except AttributeError: t = "" else: t = glocation.address data["address"] = t return json.dumps(data)