def parse_result(place): line1, line2, line3, line4 = place.get('line1'), place.get('line2'), place.get('line3'), place.get('line4') address = util.join_filter(", ", [line1, line2, line3, line4]) city = place.get('city') state = place.get('state') country = place.get('country') location = util.join_filter(", ", [address, city, country]) lat, lng = place.get('latitude'), place.get('longitude') #if lat and lng: # point = Point(floatlat, lng) #else: # point = None return (location, (float(lat), float(lng)))
def parse_result(place): line1, line2, line3, line4 = place.get('line1'), place.get( 'line2'), place.get('line3'), place.get('line4') address = util.join_filter(", ", [line1, line2, line3, line4]) city = place.get('city') state = place.get('state') country = place.get('country') location = util.join_filter(", ", [address, city, country]) lat, lng = place.get('latitude'), place.get('longitude') #if lat and lng: # point = Point(floatlat, lng) #else: # point = None return (location, (float(lat), float(lng)))
def parse_resource(resource): stripchars = ", \n" a = resource['address'] address = a.get('addressLine', '').strip(stripchars) city = a.get('locality', '').strip(stripchars) state = a.get('adminDistrict', '').strip(stripchars) zipcode = a.get('postalCode', '').strip(stripchars) country = a.get('countryRegion', '').strip(stripchars) city_state = join_filter(", ", [city, state]) place = join_filter(" ", [city_state, zipcode]) location = join_filter(", ", [address, place, country]) latitude = resource['point']['coordinates'][0] or None longitude = resource['point']['coordinates'][1] or None if latitude and longitude: latitude = float(latitude) longitude = float(longitude) return (location, (latitude, longitude))
def _parse_result(result): # turn x=y pairs ("lat=47.6", "long=-117.426") into dict key/value pairs: place = dict( filter(lambda x: len(x)>1, # strip off bits that aren't pairs (i.e. "geocoder modified" status string") map(lambda x: x.split('=', 1), result) # split the key=val strings into (key, val) tuples )) address = [ place.get('number', None), place.get('prefix', None), place.get('street', None), place.get('type', None), place.get('suffix', None) ] city = place.get('city', None) state = place.get('state', None) zip_code = place.get('zip', None) name = util.join_filter(", ", [ util.join_filter(" ", address), city, util.join_filter(" ", [state, zip_code]) ]) latitude = place.get('lat', None) longitude = place.get('long', None) if latitude and longitude: latlon = float(latitude), float(longitude) else: return None # TODO use Point/Location object API in 0.95 #if latitude and longitude: # point = Point(latitude, longitude) #else: # point = None #return Location(name, point, dict(result)) return name, latlon