def place_name(lat, lon): # Try to get cached location first db = Db() # 3km distace radious for a match cached_place_name = db.get_location_name(lat, lon, 3000) if (cached_place_name is not None): return cached_place_name lookup_place_name = None geolocation_info = reverse_lookup(lat, lon) if (geolocation_info is not None): if ('address' in geolocation_info): address = geolocation_info['address'] if ('city' in address): lookup_place_name = address['city'] elif ('state' in address): lookup_place_name = address['state'] elif ('country' in address): lookup_place_name = address['country'] if (lookup_place_name is not None): db.add_location(lat, lon, lookup_place_name) # TODO: Maybe this should only be done on exit and not for every write. db.update_location_db() return lookup_place_name
def place_name(lat, lon): # Try to get cached location first db = Db() # 3km distace radious for a match cached_place_name = db.get_location_name(lat, lon, 3000) if(cached_place_name is not None): return cached_place_name lookup_place_name = None geolocation_info = reverse_lookup(lat, lon) if(geolocation_info is not None): if('address' in geolocation_info): address = geolocation_info['address'] if('city' in address): lookup_place_name = address['city'] elif('state' in address): lookup_place_name = address['state'] elif('country' in address): lookup_place_name = address['country'] if(lookup_place_name is not None): db.add_location(lat, lon, lookup_place_name) # TODO: Maybe this should only be done on exit and not for every write. db.update_location_db() return lookup_place_name
def place_name(lat, lon): # Try to get cached location first db = Db() # 3km distace radious for a match cached_place_name = db.get_location_name(lat, lon, 3000) if cached_place_name is not None: return cached_place_name lookup_place_name = None geolocation_info = reverse_lookup(lat, lon) if geolocation_info is not None: if "address" in geolocation_info: address = geolocation_info["address"] if "city" in address: lookup_place_name = address["city"] elif "state" in address: lookup_place_name = address["state"] elif "country" in address: lookup_place_name = address["country"] if lookup_place_name is not None: db.add_location(lat, lon, lookup_place_name) # TODO: Maybe this should only be done on exit and not for every write. db.update_location_db() return lookup_place_name
def place_name(lat, lon): lookup_place_name_default = {'default': __DEFAULT_LOCATION__} if (lat is None or lon is None): return lookup_place_name_default # Convert lat/lon to floats if (not isinstance(lat, float)): lat = float(lat) if (not isinstance(lon, float)): lon = float(lon) # Try to get cached location first db = Db() # 3km distace radius for a match cached_place_name = db.get_location_name(lat, lon, 3000) # We check that it's a dict to coerce an upgrade of the location # db from a string location to a dictionary. See gh-160. if (isinstance(cached_place_name, dict)): return cached_place_name lookup_place_name = {} geolocation_info = lookup(lat=lat, lon=lon) if (geolocation_info is not None and 'address' in geolocation_info): address = geolocation_info['address'] log.info('Location: "%s"' % geolocation_info['display_name']) # gh-386 adds support for town # taking precedence after city for backwards compatibility for loc in ['hamlet', 'village', 'city', 'town', 'state', 'country']: if (loc in address): lookup_place_name[loc] = address[loc] # In many cases the desired key is not available so we # set the most specific as the default. if ('default' not in lookup_place_name): lookup_place_name['default'] = address[loc] if (lookup_place_name): db.add_location(lat, lon, lookup_place_name) # TODO: Maybe this should only be done on exit and not for every write. db.update_location_db() if ('default' not in lookup_place_name): lookup_place_name = lookup_place_name_default return lookup_place_name
def place_name(lat, lon): # Convert lat/lon to floats if not isinstance(lat, float): lat = float(lat) if not isinstance(lon, float): lon = float(lon) # Try to get cached location first db = Db() # 3km distace radious for a match cached_place_name = db.get_location_name(lat, lon, 3000) # We check that it's a dict to coerce an upgrade of the location # db from a string location to a dictionary. See gh-160. if (isinstance(cached_place_name, dict)): return cached_place_name lookup_place_name = {} geolocation_info = lookup(lat=lat, lon=lon) if (geolocation_info is not None): if ('address' in geolocation_info): address = geolocation_info['address'] for loc in ['city', 'state', 'country']: if (loc in address): lookup_place_name[loc] = address[loc] # In many cases the desired key is not available so we # set the most specific as the default. if ('default' not in lookup_place_name): lookup_place_name['default'] = address[loc] if ('default' not in lookup_place_name): lookup_place_name = 'Unknown Location' if (lookup_place_name is not {}): db.add_location(lat, lon, lookup_place_name) # TODO: Maybe this should only be done on exit and not for every write. db.update_location_db() return lookup_place_name
def place_name(lat, lon): lookup_place_name_default = {'default': __DEFAULT_LOCATION__} if (lat is None or lon is None): return lookup_place_name_default # Convert lat/lon to floats if (not isinstance(lat, float)): lat = float(lat) if (not isinstance(lon, float)): lon = float(lon) localdb_response = closestgeoname.query_closest_city( closestgeoname.DBFILENAME, lat, lon) if localdb_response is not None: return { "city": localdb_response[0], "default": localdb_response[0], "state": localdb_response[1], "country": localdb_response[2] } else: # This should only occur if the script is searching for a point # outside the maximum distance on earth. So this would mean # there is likely an error with the GNSS coordinate. But we can # continue to see if other services (MapQuest) has a way to handle it. print( "lat/long likely to be incorrect... continuing with other service") print("lat: {}, lon: {}".format(lat, lon)) pass # Try to get cached location first db = Db() # 3km distace radious for a match cached_place_name = db.get_location_name(lat, lon, 3000) # We check that it's a dict to coerce an upgrade of the location # db from a string location to a dictionary. See gh-160. if (isinstance(cached_place_name, dict)): return cached_place_name lookup_place_name = {} geolocation_info = lookup(lat=lat, lon=lon) if (geolocation_info is not None and 'address' in geolocation_info): address = geolocation_info['address'] for loc in ['city', 'state', 'country']: if (loc in address): lookup_place_name[loc] = address[loc] # In many cases the desired key is not available so we # set the most specific as the default. if ('default' not in lookup_place_name): lookup_place_name['default'] = address[loc] if (lookup_place_name): db.add_location(lat, lon, lookup_place_name) # TODO: Maybe this should only be done on exit and not for every write. db.update_location_db() if ('default' not in lookup_place_name): lookup_place_name = lookup_place_name_default return lookup_place_name