calculate_hotel_lat_long

This notebook calculates the latitude and longitude of all the hotels, and stores them in the database.


In [8]:
from geopy.geocoders import Nominatim
import pandas as pd
import connect_aws_db as cadb

In [3]:
engine = cadb.connect_aws_db(write_unicode=True)

In [9]:
geolocator = Nominatim()

In [10]:
location = geolocator.geocode("175 5th Ave NYC")

In [11]:
location.address


Out[11]:
u'Flatiron Building, 175, 5th Avenue, Flatiron, New York County, NYC, New York, 10010, United States of America'

In [12]:
print(location.latitude, location.longitude)


(40.7410861, -73.9896297241625)

In [13]:
location = geolocator.geocode("260 Whitney Ave, New Haven, CT")

In [14]:
print(location.address)
print(location.latitude, location.longitude)


Gibbs Building, 260, Whitney Avenue, East Rock, New Haven, New Haven County, Connecticut, 06518, United States of America
(41.31743095, -72.9217280437685)

In [17]:
location = geolocator.geocode("555 San Antonio Rd Mountain View, CA")
print(location.address)
print(location.latitude, location.longitude)


555, San Antonio Road, Castro City, Mountain View, Santa Clara County, California, 94040, United States of America
(37.4026171, -122.1106701)

In [18]:
location = geolocator.geocode("Row NYC Hotel New York City, NY")
print(location.address)
print(location.latitude, location.longitude)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-2f8723b43b6d> in <module>()
      1 location = geolocator.geocode("Row NYC Hotel New York City, NY")
----> 2 print(location.address)
      3 print(location.latitude, location.longitude)

AttributeError: 'NoneType' object has no attribute 'address'

Now trying Google


In [19]:
from geopy.geocoders import GoogleV3

In [20]:
ggeolocator = GoogleV3()

In [21]:
location = ggeolocator.geocode("Row NYC Hotel New York City, NY")
print(location.address)
print(location.latitude, location.longitude)


New York, NY, USA
(40.7127837, -74.0059413)

In [22]:
location = ggeolocator.geocode("Hilton Garden Inn Times Square")
print(location.address)
print(location.latitude, location.longitude)


Times Square, Manhattan, NY 10036, USA
(40.758895, -73.985131)

In [ ]: