Every line of 'how to get latitude and longitude from address in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
104 def get_coords(address, city, state): 105 try: 106 geolocator = GoogleV3(timeout=5) 107 address = "{0}, {1}, {2}".format(address, city, state) 108 location = geolocator.geocode(address, exactly_one=True) 109 lat = location.latitude 110 lon = location.longitude 111 except Exception as error: 112 raise GenericError(error) 113 114 return lat, lon, address
31 @property 32 def place_address(self): 33 adm_divs = self.get_value_by_key('subtype', 'district', 'adm_div') 34 adm_divs.reverse() 35 dist_addr = adm_divs.pop(0)['name'] 36 for div in adm_divs: 37 dist_addr = "%s, %s" % (dist_addr, div['name']) 38 return dist_addr.replace(u'\xa0', ' ')
91 def geoCoords(geoUnits): 92 newPt=geoUnits.split(',') 93 xCoord=newPt[0].strip() 94 yCoord=newPt[1].strip() 95 return('{0},{1}'.format(yCoord,xCoord))
9 def test_get_lat_long(self): 10 assert asm3.geo.get_lat_long(base.get_dbo(), "109 Greystones Road", "Rotherham", "South Yorkshire", "S60 2AH", "England") is not None
90 @staticmethod 91 def _format_address(location): 92 address_sections = [ 93 ['Street', 'StreetBuildingIdentifier'], 94 ['DistrictName'], 95 ['ZipCode', 'City'], 96 ] 97 address = [] 98 for section in address_sections: 99 components = filter(None, (location.get(k) for k in section)) 100 part = ' '.join(components) 101 address.append(part) 102 address = filter(None, address) 103 address = ', '.join(address) 104 105 return address
32 def get_local_name(self): 33 return f"{self.lat:.5f} : {self.lon:.5f}"
14 def geo_find(addr, apikey=False): 15 if not addr: 16 return None 17 18 if not apikey: 19 raise UserError(_('''API key for GeoCoding (Places) required.\n 20 Save this key in System Parameters with key: google.api_key_geocode, value: 21 Visit https://developers.google.com/maps/documentation/geocoding/get-api-key for more information. 22 ''')) 23 24 url = "https://maps.googleapis.com/maps/api/geocode/json" 25 try: 26 result = requests.get(url, params={'sensor': 'false', 'address': addr, 'key': apikey}).json() 27 except Exception as e: 28 raise UserError(_('Cannot contact geolocation servers. Please make sure that your Internet connection is up and running (%s).') % e) 29 30 if result['status'] != 'OK': 31 if result.get('error_message'): 32 _logger.error(result['error_message']) 33 error_msg = _('Unable to geolocate, received the error:\n%s' 34 '\n\nGoogle made this a paid feature.\n' 35 'You should first enable billing on your Google account.\n' 36 'Then, go to Developer Console, and enable the APIs:\n' 37 'Geocoding, Maps Static, Maps Javascript.\n' 38 % result['error_message']) 39 raise UserError(error_msg) 40 41 try: 42 geo = result['results'][0]['geometry']['location'] 43 return float(geo['lat']), float(geo['lng']) 44 except (KeyError, ValueError): 45 return None
244 @property 245 def latitude(self): 246 "90 > Latitude > -90" 247 return self._latitude
100 def reverse_geocode(lat, lng): 101 """Reverse geocoding using Google API 102 103 Returns a string that is the address or None if geocoding fails 104 """ 105 url = "https://maps.googleapis.com/maps/api/geocode/json" 106 payload = { 107 'latlng': str(lat)+','+str(lng), 108 'key': current_app.config['GOOGLE_GEOCODE_KEY'] 109 } 110 r = requests.get(url, params=payload) 111 112 # Google's geocode api is limited to 10 requests a second 113 if r.json()['status'] == 'OVER_QUERY_LIMIT': 114 time.sleep(1) 115 r = requests.get(url, params=payload) 116 117 if r.json()['status'] == 'ZERO_RESULTS' or len(r.json()['results']) is 0: 118 print (r.json()) 119 return None 120 else: 121 address = r.json()['results'][0]['formatted_address'] 122 return address
283 def get_location(self): 284 return type( 285 "Geocoder", 286 (object,), 287 {"centroid": Point(-2.54333651887832, 51.43921783606831, srid=4326)}, 288 )