本文整理匯總了Python中geocoder.google方法的典型用法代碼示例。如果您正苦於以下問題:Python geocoder.google方法的具體用法?Python geocoder.google怎麽用?Python geocoder.google使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類geocoder
的用法示例。
在下文中一共展示了geocoder.google方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_geocoding_with_proximity
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_geocoding_with_proximity():
# query google first to get a bbox
urls = [
# when testing locally
'https://maps.googleapis.com/maps/api/geocode/json?language=&address=Ottawa,%20Ontario&bounds=&components=®ion=&key=mock',
# when building in Travis (secured connection implies ordered parameters)
'https://maps.googleapis.com/maps/api/geocode/json?client=[secure]&latlng=45.4215296%2C+-75.697193&sensor=false&signature=iXbq6odmrYN0XgcfB5EPcgEvR-I%3D'
]
data_file = 'tests/results/google.json'
with requests_mock.Mocker() as mocker, open(data_file, 'r') as input:
for url in urls:
mocker.get(url, text=input.read())
google = geocoder.google(location, client=None, key='mock')
# query geonames with bbox
url = 'http://api.geonames.org/searchJSON?q=Ottawa%2C+Ontario&fuzzy=1.0&username=mock&maxRows=1&east=-75.2465979&west=-76.3539158&north=45.5375801&south=44.962733'
data_file = 'tests/results/geonames_proximity.json'
with requests_mock.Mocker() as mocker, open(data_file, 'r') as input:
mocker.get(url, text=input.read())
g = geocoder.geonames(location, key='mock', proximity=google.bbox)
assert g.ok
示例2: get_site_addr_loc
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def get_site_addr_loc(tags, site_id, session):
show_google_map = False
addr_loc = None
site_address = ""
allowed_tags = ['geoCity', 'geoCountry', 'geoPostalCode', 'geoState', 'geoStreet', 'geoAddr']
geo_addr = None
if settings.GOOGLE_API_KEY:
if tags:
for tag in tags:
if tag in allowed_tags and tags[tag]:
if tag == 'geoAddr':
geo_addr = tags[tag]
continue
if site_address:
site_address = site_address + ", "
site_address = site_address + tags[tag]
if tag == 'geoStreet':
show_google_map = True
if not show_google_map and geo_addr:
if site_address:
site_address = site_address + ", "
site_address = site_address + geo_addr
show_google_map = True
if site_address and show_google_map:
hash_object = hashlib.md5(site_address.encode('utf-8'))
hash_key = hash_object.hexdigest()
if hash_key in session:
addr_loc = session[hash_key]
if not addr_loc:
geo = geocoder.google(site_address, key=settings.GOOGLE_API_KEY)
if geo.json and geo.json["ok"]:
addr_loc = {"latitude": geo.json["lat"], "longitude": geo.json["lng"], "site_id": site_id}
session[hash_key] = addr_loc
return addr_loc
示例3: test_entry_points
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_entry_points():
geocoder.ip
geocoder.osm
geocoder.w3w
geocoder.bing
geocoder.here
geocoder.tgos
geocoder.baidu
geocoder.gaode
geocoder.yahoo
geocoder.mapbox
geocoder.google
geocoder.yandex
geocoder.tomtom
geocoder.arcgis
geocoder.ipinfo
geocoder.mapzen
geocoder.geonames
geocoder.mapquest
geocoder.timezone
geocoder.maxmind
geocoder.elevation
geocoder.freegeoip
geocoder.geolytica
geocoder.timezone
geocoder.opencage
geocoder.places
geocoder.canadapost
geocoder.tamu
geocoder.geocodefarm
geocoder.uscensus
示例4: test_unicode
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_unicode():
g = geocoder.google('東京', key='')
assert g
示例5: test_session
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_session():
with requests.Session() as session:
g = geocoder.google(address, session=session)
assert g.ok
osm_count, fields_count = g.debug()[0]
assert osm_count >= 4
assert fields_count >= 16
示例6: test_session_called
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_session_called():
with mock.patch('requests.Session.get'):
with requests.Session() as session:
geocoder.google(address, session=session)
session.get.assert_called_once()
示例7: test_issue_294
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_issue_294():
g = geocoder.google("Cerro Torre Mountain")
assert g.ok
示例8: test_google_reverse
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_google_reverse():
g = geocoder.google(ottawa, method='reverse')
assert g.ok
assert len(g) >= 10
示例9: test_google_places
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_google_places():
g = geocoder.google(place, method='places')
assert g.ok
assert g.address == '200 Tremblay Rd, Ottawa, ON K1G 3H5, Canada'
示例10: test_google_timezone
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_google_timezone():
url = 'https://maps.googleapis.com/maps/api/timezone/json?location=45.4215296%2C+-75.697193×tamp=1500000000'
data_file = 'tests/results/google_timezone.json'
with requests_mock.Mocker() as mocker, open(data_file, 'r') as input:
mocker.get(url, text=input.read())
g = geocoder.google(ottawa, method='timezone', timestamp=1500000000)
assert g.ok
示例11: test_google_elevation
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def test_google_elevation():
url = 'https://maps.googleapis.com/maps/api/elevation/json?locations=45.4215296%2C+-75.697193'
data_file = 'tests/results/google_elevation.json'
with requests_mock.Mocker() as mocker, open(data_file, 'r') as input:
mocker.get(url, text=input.read())
g = geocoder.google(ottawa, method='elevation')
assert g.ok
示例12: find_therapist
# 需要導入模塊: import geocoder [as 別名]
# 或者: from geocoder import google [as 別名]
def find_therapist():
"""This function uses the Google Places API to recommend a therapist based on the user's location. """
keyword = "counseling OR therapist OR psychiatrist"
try:
address = get_alexa_location()
pass
except:
return statement("""Hmm. It appears that I can't find your location. Please allow access to your "
location in the Alexa app and try again """).consent_card("read::alexa:device:all:address")
g = geocoder.google(address)
latlng = g.latlng
location = "{},{}".format(latlng[0], latlng[1])
print(location)
key = "AIzaSyA1yY-DOHIun0v_7kTwa_U5Ah6Am-kcjCM"
URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(location,keyword,key)
print(URL2)
r2 = requests.get(URL2)
if r2.status_code == 200:
first_output = r2.json()
else:
return "Sorry, I'm having trouble doing that right now. Please try again later."
results = first_output['results']
idnum = (results[1]['place_id'])
name = (results[1]['name'])
# print(results[1])
# print(idnum)
URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(idnum, key)
r3 = requests.get(URL3)
if r3.status_code == 200:
second_output = r3.json()
phone = (second_output['result'])['international_phone_number']
# print(second_output)
# print(phone)
session.attributes["State"] = "Null"
message = """I've found a therapist near you. Their name is: {}, and their number is: {}. I've added their
contact info to a card in the Alexa app. Is there anything else I can do?""".format(name,phone)
card = "Name:{} \n Phone:{}".format(name,phone)
return question(message).standard_card(title="I've found you a possible therapist",
text=card,
large_image_url="https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80")
else:
return statement("Sorry, I'm having trouble doing that right now. Please try again later.")