本文整理汇总了Python中googlemaps.GoogleMaps.address_to_latlng方法的典型用法代码示例。如果您正苦于以下问题:Python GoogleMaps.address_to_latlng方法的具体用法?Python GoogleMaps.address_to_latlng怎么用?Python GoogleMaps.address_to_latlng使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类googlemaps.GoogleMaps
的用法示例。
在下文中一共展示了GoogleMaps.address_to_latlng方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distances
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def distances(start_address,end_address):
gmaps = GoogleMaps()
base_url = 'http://maps.googleapis.com/maps/api/directions/json?'
travel_mode='mode=walking'
if start_address==end_address:
return False
start_lat, start_longt = gmaps.address_to_latlng(start_address+', New York, USA') #Getting the longtitudes and lattitudes of given addresses
end_lat, end_longt = gmaps.address_to_latlng(end_address+', New York, USA')
sensor='sensor=false'
test_url=base_url+'&'+travel_mode+'&'+'origin='+str(start_lat)+','+str(start_longt)+'&destination='+str(end_lat)+','+str(end_longt)+'&'+sensor #Constructs the url to query google maps for walking directions
print test_url
result = json.load(urllib.urlopen(test_url))
met_distance = result['routes'][0]['legs'][0]['distance']['value'] #obtain the walking distance in km
print 'Metropolitan distance between ', start_address, 'and', end_address , ' is ',met_distance, 'm'
#calculate the straight line distance (over the surface of the Earth) assuming the Earth is a sphere of radius 6378100m
dlat = m.radians(end_lat-start_lat)
dlongt = m.radians(end_longt-start_longt)
a = ((m.sin(dlat/2))*(m.sin(dlat/2)))+(m.cos(m.radians(start_lat)) * m.cos(m.radians(end_lat)) * (m.sin(dlongt/2))*(m.sin(dlongt/2)) )
c = 2 * m.atan2(m.sqrt(a), m.sqrt(1-a))
d = 6378100 * c
print 'Whereas line of flight distance is' , d,'m'
if d == 0 : return False
rat = met_distance/d
if rat < 1 : rat = 1
return rat
示例2: get_location
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def get_location(zipcode):
gmaps = GoogleMaps(API_key)
latlong = gmaps.address_to_latlng(zipcode)
return latlong
示例3: lookup
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def lookup(request):
what = (request.POST['what']).lower()
where = (request.POST['where']).lower()
api = twython.setup('Basic', username='U_Need', password='')
gmaps = GoogleMaps()
mentions = api.getUserMentions(since_id=4698625520)
a = []
lat1, lng1 = gmaps.address_to_latlng(where)
#if is not (api):
# render_to_response('need/enter.html')
for stat in mentions:
text = (stat["text"]).lower()
ele = text.split(':')
lat2 = float(ele[2])
lng2 = float(ele[3])
if (text.find(what) != -1) and (in_vic(lat1, lng1, lat2, lng2) == 1):
actual = gmaps.latlng_to_address(lat2, lng2)
tweet = ele[1] + " " + actual
a.append(tweet)
t = loader.get_template("need/results.html")
c = Context({'stat': a},)
return HttpResponse(t.render(c))
示例4: add_case
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def add_case( self, case ):
from googlemaps import GoogleMaps
from time import sleep
gmaps = GoogleMaps()
for casa in case:
casa['cap'] = int( casa['cap'] )
sleep( 0.2 )
print "Calcolo latitudine/longitudine"
( casa['latitudine'],
casa['longitudine'] ) = gmaps.address_to_latlng( "%s %d, %s, %s" % (
casa['indirizzo'], casa['cap'],
casa['comune'], casa['provincia'] ) )
casa['allegati'] = casa['allegati'].replace(' ',',')
casa['tipo'] = casa['vendita'].upper()
del( casa['vendita'] )
casa['base'] = int( casa['costo'].replace('.','').split(',')[0] )
del( casa['costo'] )
self.conn.insert( 'case', casa )
print
示例5: post
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def post(self):
models.Difficulty.load()
models.User.get_test_user()
self.redirect(Index.url)
cat = models.Category(name="Food/Beverage", description="")
cat.put()
subcat = models.Category(name="Resturant", description="", parent_category=cat)
subcat.put()
subcat = models.Category(name="Coffee House", description="", parent_category=cat)
subcat.put()
red = models.Location(owner=self.current_user, location=db.GeoPt(37, -122))
red.address = "310 SW 3rd Street"
red.name = "Red Horse"
red.description = "Red Horse Coffee"
red.category = subcat
red.city = "Corvallis"
red.state = "OR"
red.zip = "97333"
red.county = "USER"
red.phone_number = "(541) 757-3025"
red.rating = 99
red.put()
gmaps = GoogleMaps(self.enviroment.google_maps_key)
lat, lng = gmaps.address_to_latlng(red.get_address())
red.update_location(db.GeoPt(lat, lng))
red.save()
示例6: do_post
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def do_post(self):
address = self.param('address')
lat = self.param('lat')
lon = self.param('lon')
miles = self.request.get('miles', default_value=10)
max_results = self.request.get('max_results', default_value=10)
geoPoint = None
try:
if address:
try:
gmaps = GoogleMaps(self.enviroment.google_maps_key)
lat, lon = gmaps.address_to_latlng(address)
except:
self.write_error('Cannot get position from address')
return
geoPoint = db.GeoPt(lat, lon)
except:
self.write_error('Error validating position')
return
if geoPoint:
meters = float(miles) * base.METERS_IN_MILE
locations = models.Location.proximity_fetch( models.Location.all(), geoPoint, int(max_results), meters )
if locations and len(locations) > 0:
json = []
for loc in locations:
json.append(loc.to_json_object())
self.write_success(json)
else:
self.write_error("No Locations within %s miles" % miles)
示例7: _geo_loc
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def _geo_loc(self, cr, uid, ids, field_name, arg, context):
result = {}
gmaps = GoogleMaps("http://maps.googleapis.com/maps/api/js?key=AIzaSyBwNE-vFDyyOb62ODaRiqpiL2kz8wR0aTc")
for partner in self.browse(cr,uid,ids):
address = partner.street
lat, lng = gmaps.address_to_latlng(address)
latlng = str(lat) +","+ str(lng)
result[partner.id] = str(latlng)
return result
示例8: getMap
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def getMap(businessid):
GOOGLEMAPS_API_KEY = settings.GOOGLEMAPS_API_KEY
gmaps = GoogleMaps(GOOGLEMAPS_API_KEY)
business = Businesses.objects.filter(businessID = businessid)[0]
address = business.street + ' ' + business.city + ' ' + str(business.zipCode)
lat, lng = gmaps.address_to_latlng(address)
return lat,lng
示例9: returnCoordinate
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def returnCoordinate(tweets):
gmaps = GoogleMaps('AIzaSyB8YS_1RgpdLZogrpNsZ6V7Yc6mKJAE_og')
updated=[]
for tweet in tweets:
location=re.search('where:([\w]+)', lower(tweet['text']))
if location:
address = location.group(1)
lat, lng = gmaps.address_to_latlng(address)
updated.append([location, lat, lng])
return updated
示例10: FindPizza
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def FindPizza():
print "Enter in an address to find Pizza places near it"
address = raw_input()
gmaps = GoogleMaps("AIzaSyA5R4PnzAcoe2vpVRKyWWby-d6RrMmIwtQ")
lat, lng = gmaps.address_to_latlng(address)
destination = gmaps.latlng_to_address(lat, lng)
Pizza = gmaps.local_search('pizza near ' + destination)
directions = gmaps.directions(address, destination)
print "The nearest Pizza place is " + Pizza['responseData']['results'][0]['titleNoFormatting']
for step in directions['Directions']['Routes'][0]['Steps']:
print step['descriptionHtml']
示例11: createMap
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def createMap(self):
gmaps = GoogleMaps("ABQIAAAAQQRAsOk3uqvy3Hwwo4CclBTrVPfEE8Ms0qPwyRfPn-DOTlpaLBTvTHRCdf2V6KbzW7PZFYLT8wFD0A")
address = self.location
lat, lng = gmaps.address_to_latlng(address)
m = pymaps.PyMap(lat, lng)
m.key = "ABQIAAAAQQRAsOk3uqvy3Hwwo4CclBTrVPfEE8Ms0qPwyRfPn-DOTlpaLBTvTHRCdf2V6KbzW7PZFYLT8wFD0A"
m.maps[0].zoom = 17
q = [lat,lng, 'Search Result Location: '+ address]
m.maps[0].setpoint(q)
open('test.html','wb').write(m.showhtml()) # generate test file
webbrowser.open('test.html')
示例12: get_loc
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def get_loc(address):
api_key = "ABQIAAAA_Nl9CTT83Tx0_6m45f7SQxRfRo7TXTpgZcKZw6sB7U7ZlfQK2BQV36qlGpf3-HF0Ntlqdf8T-Gaqxg"
gmaps = GoogleMaps(api_key)
lat, lng = gmaps.address_to_latlng(address)
print lat, lng
return lat, lng
示例13: lugarnuevo
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def lugarnuevo(request):
if request.method == 'POST':
formulario = LugarNuevo(request.POST)
if formulario.is_valid():
#Obtencion de valores del formulario para generar el XML
direccion = formulario.cleaned_data['direccion']
print direccion
poblacion = formulario.cleaned_data['poblacion']
print poblacion
nombre = formulario.cleaned_data['nombre']
print nombre
tipo = formulario.cleaned_data['tipo']
print tipo
gmaps = GoogleMaps('AIzaSyCNUf4Y4LBWWkQAYSvJmQCriCzNmEJkD0A')
direccion = direccion + ',' + poblacion
lat, lng = gmaps.address_to_latlng(direccion)
lat = str(lat)
lng = str(lng)
if tipo == '1':
tipo = 'bar'
elif tipo == '2':
tipo = 'cafeteria'
elif tipo == '3':
tipo = 'comida'
elif tipo == '4':
tipo = 'restaurante'
print tipo
xml = "<PlaceAddRequest>" + "<location>" + "<lat>" + \
lat + \
"</lat>" + "<lng>" + lng + "</lng>" + \
"</location>" + \
"<accuracy>" + "5" + "</accuracy>" + \
"<name>" + nombre + "</name>" + \
"<type>" + tipo + "</type>" + \
"<language>" + "es" + "</language>" + \
"</PlaceAddRequest>"
#print xml
##utilizamos request, una libreria mas optimizada que urllib2
#r = requests.post('https://maps.googleapis.com/maps/api/place/ \
#add/xml?sensor=false&key= \
#AIzaSyCNUf4Y4LBWWkQAYSvJmQCriCzNmEJkD0A', xml)
#print r.content
url = 'https://maps.googleapis.com/maps/api/place/add/xml?sensor=false&key=AIzaSyCNUf4Y4LBWWkQAYSvJmQCriCzNmEJkD0A'
req = urllib2.Request(url,
xml,
headers={'Content-Type': 'application/xml'})
consulta = urllib2.urlopen(req)
print consulta.read()
else:
formulario = LugarNuevo()
return render_to_response('lugarnuevo.html', {'formulario': formulario},
context_instance=RequestContext(request))
示例14: tweet
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def tweet(request):
api = twython.setup('Basic', request.session['username'], request.session['password'])
gmaps = GoogleMaps()
what = request.POST['what']
where = request.POST['where']
lat, lng = gmaps.address_to_latlng(where)
tweet = "@U_Need :" + what + ":" + str(lat) + ':' + str(lng) + ":#ihave"
api.updateStatus(tweet)
return render_to_response('have/add.html')
示例15: __init__
# 需要导入模块: from googlemaps import GoogleMaps [as 别名]
# 或者: from googlemaps.GoogleMaps import address_to_latlng [as 别名]
def __init__(self, thing_id=None, streetAddress=None, city=None, state=None, zipCode=None):
googleMapsAddress = str(streetAddress) + " " + str(city) + " " + str(state) + " "+ str(zipCode)
pprint.pprint( googleMapsAddress)
gmaps = GoogleMaps(googleMapsApi_key)
lat, lng = gmaps.address_to_latlng(googleMapsAddress)
print lng
print lat
self.thing_id = thing_id
self.latitude = lat
self.longitude = lng
self.zipCode = zipCode
self.state = state
self.city = city
self.streetAddress = streetAddress