def geocode(q, api_key, ll=None, spn=None, rspn=None, plng=None): args = { 'geocode': q, 'key': api_key, 'results': 1, 'format': 'json', } if plng: args['plng'] = plng if ll and spn: ll = hasattr(ll, '__iter__') and ','.join(map(str, ll)) or ll args['ll'] = ll spn = hasattr(spn, '__iter__') and ','.join(map(str, spn)) or spn args['spn'] = spn if rspn and ll and spn: args['rspn'] = rspn url = 'http://geocode-maps.yandex.ru/1.x/?%s' % urllib.urlencode(args) json = simplejson.load(urllib.urlopen(url)) try: member = json['response']['GeoObjectCollection']['featureMember']\ [0]['GeoObject'] return ( member['metaDataProperty']['GeocoderMetaData']['text'], tuple(map(float, member['Point']['pos'].split(' ')[::-1])) ) except (KeyError, IndexError): return (None, (None, None))
def geocode(lat, lon): json = simplejson.load(urllib.urlopen( 'http://maps.googleapis.com/maps/api/geocode/json?' + urllib.urlencode({ 'latlng': '%s,%s' % (lat, lon), 'sensor': 'false', 'language': 'cs' }) )) return json
def geocode(lat, lon): json = simplejson.load( urllib.urlopen('http://maps.googleapis.com/maps/api/geocode/json?' + urllib.urlencode({ 'latlng': '%s,%s' % (lat, lon), 'sensor': 'false', 'language': 'cs' }))) return json
def geocode(q, api_key): base_url = "http://developer.multimap.com/API/geocode/1.2/%s" % urllib.quote(api_key) json = simplejson.load(urllib.urlopen(base_url + "?" + urllib.urlencode({"qs": q, "output": "json"}))) try: lon = json["result_set"][0]["point"]["lon"] lat = json["result_set"][0]["point"]["lat"] except (KeyError, IndexError): return RichResult((None, (None, None)), data=None) name = json["result_set"][0]["address"]["display_name"] return RichResult((name, (lat, lon)), data=json)
def geocode(q, api_key): json = simplejson.load(urllib.urlopen( 'http://maps.google.com/maps/geo?' + urllib.urlencode({ 'q': q.encode('utf-8'), 'output': 'json', 'oe': 'utf8', 'sensor': 'false', 'key': api_key, 'hl': 'cs' }) )) return json
def geocode(q, api_key): json = simplejson.load( urllib.urlopen('http://maps.google.com/maps/geo?' + urllib.urlencode({ 'q': q.encode('utf-8'), 'output': 'json', 'oe': 'utf8', 'sensor': 'false', 'key': api_key, 'hl': 'cs' }))) return json
def geocode(q, api_key): json = simplejson.load( urllib.urlopen( "http://maps.google.com/maps/geo?" + urllib.urlencode({"q": q, "output": "json", "oe": "utf8", "sensor": "false", "key": api_key}) ) ) try: lon, lat = json["Placemark"][0]["Point"]["coordinates"][:2] except (KeyError, IndexError): return RichResult((None, (None, None)), data=None) name = json["Placemark"][0]["address"] return RichResult((name, (lat, lon)), data=json)
def geocode(q, api_key=None): json = simplejson.load(urllib.urlopen( 'http://maps.googleapis.com/maps/api/geocode/json?' + urllib.urlencode({ 'address': q, 'sensor': 'false', }) )) try: lon = json['results'][0]['geometry']['location']['lng'] lat = json['results'][0]['geometry']['location']['lat'] except (KeyError, IndexError): return None, (None, None) name = json['results'][0]['formatted_address'] return name, (lat, lon)
def geocode(q, api_key=None): json = simplejson.load( urllib.urlopen('http://maps.googleapis.com/maps/api/geocode/json?' + urllib.urlencode({ 'address': q, 'sensor': 'false', }))) try: lon = json['results'][0]['geometry']['location']['lng'] lat = json['results'][0]['geometry']['location']['lat'] except (KeyError, IndexError): return None, (None, None) name = json['results'][0]['formatted_address'] return name, (lat, lon)
def geocode(q, api_key): base_url = 'http://developer.multimap.com/API/geocode/1.2/%s' % urllib.quote(api_key) json = simplejson.load(urllib.urlopen(base_url + '?' + urllib.urlencode({ 'qs': q, 'output': 'json' }) )) try: lon = json['result_set'][0]['point']['lon'] lat = json['result_set'][0]['point']['lat'] except (KeyError, IndexError): return None, (None, None) name = json['result_set'][0]['address']['display_name'] return name, (lat, lon)
def geocode(q): data = simplejson.load( urllib.urlopen( "http://ws.geonames.org/searchJSON?" + urllib.urlencode({"q": q, "maxRows": 1, "lang": "en", "style": "full"}) ) ) if not data["geonames"]: return RichResult((None, (None, None)), data=None) place = data["geonames"][0] name = place["name"] if place["adminName1"] and place["name"] != place["adminName1"]: name += ", " + place["adminName1"] return RichResult((name, (place["lat"], place["lng"])), data=data)
def geocode(q, api_key): base_url = 'http://developer.multimap.com/API/geocode/1.2/%s' % urllib.quote( api_key) json = simplejson.load( urllib.urlopen(base_url + '?' + urllib.urlencode({ 'qs': q, 'output': 'json' }))) try: lon = json['result_set'][0]['point']['lon'] lat = json['result_set'][0]['point']['lat'] except (KeyError, IndexError): return None, (None, None) name = json['result_set'][0]['address']['display_name'] return name, (lat, lon)
def geocode(q, api_key): json = simplejson.load( urllib.urlopen('http://maps.google.com/maps/geo?' + urllib.urlencode({ 'q': q, 'output': 'json', 'oe': 'utf8', 'sensor': 'false', 'key': api_key }))) try: lon, lat = json['Placemark'][0]['Point']['coordinates'][:2] except (KeyError, IndexError): return None, (None, None) name = json['Placemark'][0]['address'] return name, (lat, lon)
def geocode(q, api_key): json = simplejson.load(urllib.urlopen( 'http://maps.google.com/maps/geo?' + urlencode({ 'q': q, 'output': 'json', 'oe': 'utf8', 'sensor': 'false', 'key': api_key }) )) try: lon, lat = json['Placemark'][0]['Point']['coordinates'][:2] except (KeyError, IndexError): return None, (None, None) name = json['Placemark'][0]['address'] return name, (lat, lon)
def geocode(q): data = simplejson.load( urllib.urlopen('http://ws.geonames.org/searchJSON?' + urlencode({ 'q': q, 'maxRows': 1, 'lang': 'en', 'style': 'full' }))) if not data['geonames']: return None, (None, None) place = data['geonames'][0] name = place['name'] if place['adminName1'] and place['name'] != place['adminName1']: name += ', ' + place['adminName1'] return name, (place['lat'], place['lng'])
def geocode(q): data = simplejson.load(urllib.urlopen( 'http://ws.geonames.org/searchJSON?' + urllib.urlencode({ 'q': q, 'maxRows': 1, 'lang': 'en', 'style': 'full' }) )) if not data['geonames']: return None, (None, None) place = data['geonames'][0] name = place['name'] if place['adminName1'] and place['name'] != place['adminName1']: name += ', ' + place['adminName1'] return name, (place['lat'], place['lng'])
def geocode(q, email): """ Geocode a location query using OpenStreetMap's Nominatim API. Pass an email address, as a courteous gesture, to allow the OSM admins to contact you if you are using too many resources. """ json = simplejson.load( urllib.urlopen('http://nominatim.openstreetmap.org/search?' + urllib.urlencode({ 'q': q, 'format': 'json', 'email': email }))) try: lon, lat = json[0]['lon'], json[0]['lat'] except (KeyError, IndexError): return None, (None, None) name = json[0]['display_name'] return name, (lat, lon)
def geocode(q, email): """ Geocode a location query using OpenStreetMap's Nominatim API. Pass an email address, as a courteous gesture, to allow the OSM admins to contact you if you are using too many resources. """ json = simplejson.load(urllib.urlopen( 'http://nominatim.openstreetmap.org/search?' + urllib.urlencode({ 'q': q, 'format': 'json', 'email': email }) )) try: lon, lat = json[0]['lon'], json[0]['lat'] except (KeyError, IndexError): return None, (None, None) name = json[0]['display_name'] return name, (lat, lon)
def geocode(q, api_key): json = simplejson.load(urllib.urlopen( 'http://maps.google.com/maps/geo?' + urllib.urlencode({ 'q': q, 'output': 'json', 'oe': 'utf8', 'sensor': 'false', 'key': api_key }) )) if json['Placemark'][0]['AddressDetails']['Accuracy'] > 7 and json['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName'] == 'NY': try: lon, lat = json['Placemark'][0]['Point']['coordinates'][:2] name = json['Placemark'][0]['address'] try: zc = json['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['Locality']['PostalCode']['PostalCodeNumber'] except: zc = json['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['PostalCode']['PostalCodeNumber'] return name, (lon, lat), zc except: raise GeocodeError("No results from geocoder") else: raise GeocodeError("No results from geocoder")