def main():
    woosmap_converted_asset = []
    with codecs.open(SEARCH_DATA_PATH, 'rb',
                     encoding='utf8') as search_data_file:
        search_data = json.loads(search_data_file.read())
        google_places = GooglePlaces(GOOGLE_API_KEY)
        for place_id in search_data['places_ids']:
            try:
                place = google_places.get_place(place_id)
                converted_asset = google_places_to_woosmap(place.details)
                if bool(converted_asset):
                    print("... {place_name} ...converted to Wosmap OK".format(
                        place_name=place.name.encode('utf-8')))
                    woosmap_converted_asset.append(converted_asset)

            except (GooglePlacesError,
                    GooglePlacesAttributeError) as error_detail:
                print(
                    'Google Returned an Error : {0} for Place ID : {1}'.format(
                        error_detail, place_id))
                pass

            except Exception as exception:
                print('Exception Returned {0} for Place ID : {1}'.format(
                    exception, place_id))
                time.sleep(1)
                pass

        export_to_woosmap_json(woosmap_converted_asset)
        print('{0} google places extracted for {1} places_ids found '.format(
            len(woosmap_converted_asset), len(search_data['places_ids'])))
示例#2
0
def getOneWaypoint(waypoint, reference = None):
    pool = ConnectionPool('vendalize')
    cfmapWaypoint = pycassa.ColumnFamilyMap(data.Waypoint, pool, 'waypoints')    #map waypoints to Waypoint Class
    si = sunburnt.SolrInterface("http://54.225.230.44:8983/solr/vendalize.waypoints/")
    wp = waypoint.lower()
    wp = re.sub('[^\w\s]+','', wp)
    response = si.query(waypoint_c=wp).execute(constructor=data.Waypoint)
    if len(response) > 0:   #found waypoint in database so use the googleid as reference for data
        result = response[0]
        key = result.key
        reference = result.googlereference
    
    google_places = GooglePlaces(config.Config.googlePlacesAPIKey)
    place = {}
    if reference:
        place = google_places.get_place(reference)
        if not place:
            return getOneWaypoint(waypoint, None)   #reference lookup failed, try text search
    else:
        query_result = google_places.text_search(
            query = waypoint)
        if len(query_result.places) > 0:
            place = (query_result.places)[0]
            place.get_details()
        
    return place
def main():
    woosmap_converted_asset = []
    with codecs.open(SEARCH_DATA_PATH, 'rb', encoding='utf8') as search_data_file:
        search_data = json.loads(search_data_file.read())
        google_places = GooglePlaces(GOOGLE_API_KEY)
        for place_id in search_data['places_ids']:
            try:
                place = google_places.get_place(place_id)
                converted_asset = google_places_to_woosmap(place.details)
                if bool(converted_asset):
                    print("... {place_name} ...converted to Wosmap OK".format(place_name=place.name.encode('utf-8')))
                    woosmap_converted_asset.append(converted_asset)

            except (GooglePlacesError, GooglePlacesAttributeError) as error_detail:
                print('Google Returned an Error : {0} for Place ID : {1}'.format(error_detail, place_id))
                pass

            except Exception as exception:
                print('Exception Returned {0} for Place ID : {1}'.format(exception, place_id))
                time.sleep(1)
                pass

        export_to_woosmap_json(woosmap_converted_asset)
        print('{0} google places extracted for {1} places_ids found '.format(len(woosmap_converted_asset),
                                                                             len(search_data['places_ids'])))
class GoogleHelper:
    """
    Helper class for accessing the google API
    """
    def __init__(self, gmaps_api_key=None):
        if gmaps_api_key is None:
            from config import config
            gmaps_api_key = config["gmapsApiKey"]

        self.google_places = GooglePlaces(gmaps_api_key)

    def get_pois(self, lat_lng, radius, type_list):
        """
        location: must be given in latitutde-longitude
        radius: distance in meters within which to return plae results
        types: What type of point of interest (examples: TYPE_FOOD)
        return: List of GooglePlacesSearchResults.
        """
        results = []
        for t in type_list:
            res = self.google_places.nearby_search(lat_lng=lat_lng,
                                                   type=t,
                                                   radius=radius)
            results.extend(res.places)

        # if query_result.has_attributions:
        #     return query_result.html_attributions

        return results

    def get_pois_features(self, place_id: str):
        """
        Gets safety, elevation, other attributes for a given point of interest
        """
        query_result = self.google_places.get_place(place_id)

        return query_result

    def get_pois_reviews(self, place_id):
        """
        Gets ratings for a point of interest, returns json
        """
        query_result = self.google_places.get_place(place_id)

        return query_result.rating
示例#5
0
def add_location_to_restaurants():
    from .models import Restaurant
    from googleplaces import GooglePlaces, types, lang, GooglePlacesError
    gplaces = GooglePlaces(GOOGLE_PLACES_API_KEY)
    #find all the restaurants that don't have location codes.
    nonlocated_restaurants = Restaurant.objects.filter(
        Q(latitude__isnull=True) | Q(longitude__isnull=True) )

    #iterates through; doesn't need to be a Bulk insert as background task run overnight
    for restaurant in nonlocated_restaurants:
        try:
            current_place = gplaces.get_place(restaurant.location_code)
            restaurant.latitude = current_place.geo_location['lat']
            restaurant.longitude = current_place.geo_location['lng']
            restaurant.save()
        except GooglePlacesError:
            print "Errored out on ", restaurant, " location code was: ", restaurant.location_code
    return "Completed"
示例#6
0
    def VisitedPlaces(self, lat, lng):
        placesVisited = []

        google_places = GooglePlaces(API_KEY)
        location = {'lat': lat, 'lng': lng}

        query_result = google_places.nearby_search(lat_lng=location,
                                                   radius=RADIUS)

        placesIds = []
        for place in query_result.places:
            # Returned places from a query are place summaries.
            placesIds.append(place.place_id)

        for placeid in placesIds:
            place_query_result = google_places.get_place(placeid)

            placeVisited = {
                #                'formatted_address': place_query_result.formatted_address,
                'place_types': place_query_result.types
            }

            placesVisited.append(placeVisited)

        # Iterate through our list of placetypes of interest
        for search_place_type in PlaceTypeList:
            # Iterate through our list of places visited
            #print search_place_type
            for place_visited in placesVisited:
                # Iterate through the list of places types for the current place visited
                #print place_visited
                for returned_place_type in place_visited['place_types']:
                    # Check if the returned place type is one that we are searching for
                    #print returned_place_type
                    if returned_place_type == search_place_type:
                        #print 'match found'
                        # Get the return score from the dictionary
                        returned_score = dic_place_types_scores[
                            search_place_type]
                        # Return the score
                        return returned_score

        return ZERO
示例#7
0
def get_place_details(place_id, key):

    place = None
    google_places = GooglePlaces(key)

    while (place is None):
        try:
            place = google_places.get_place(place_id)

        except Exception as e:

            # check for NOT FOUND error (place not found)
            if 'NOT_FOUND' in e.message:
                print 'Place not found error - ' + place_id
                return None  # return back to caller
            else:
                print 'sleeping for ' + place_id + ' using key: ' + key + " : " + str(
                    e.message)
                time.sleep(3)
                place = None
                key = random.choice(new_keys)
                google_places = GooglePlaces(key)

    return place
示例#8
0
def api():
    # Google API Key for places
    API_KEY = "AIzaSyBM7aOj21cM0LyY07I0EDBSpTNwFrYxlfU"

    # Google Place ID for development testing
    our_place = "ChIJU15olDoGwYkR5V4cJDvVpuI"

    # Yelp Keys
    clientid = "jSrFJLrPGi5-n3JuO-ySFA"
    clientsecret = "WS5tdjDSzoiXSgm8q9UyogiuYbYSUzjHsDlhluP4rvsp9pohCmuFDIodNCM1gW05"

    # Yelp Object
    yelp = YelpAPI(clientid, clientsecret)

    # Google Object
    google = GooglePlaces(API_KEY)

    # Only gives name, lat & lng
    place = google.get_place(place_id=our_place)
    pprint(place.details)
    print(place.details['address_components'][0]['long_name'])
    print(place.details['address_components'][1]['long_name'])
    print(place.details['address_components'][2]['short_name'])
    print(place.details['address_components'][5]['short_name'])
    #print(place.details['address_components'][7]['long_name'])
    #print(place.details['address_components'][6]['short_name'])
    print(place.details['international_phone_number'])
    print(place.details['name'])

    if our_place == place.place_id:
        print('Yes')

    addr = place.details['formatted_address'].split(",")
    print(addr)
    print(addr[0], addr[1], addr[2][1:3].strip(), addr[2][4:9], addr[3])
    print(len(addr[2][1:3].strip()))
示例#9
0
class MapsAPI:
    TRAVEL_BY = {
        0: 'walking',
        1: 'bicycling',
        2: 'transit',
        3: 'driving',
        4: 'flight'
    }

    def __init__(self, API_KEY):
        self.gmaps = googlemaps.Client(key=API_KEY,
                                       queries_per_second=50,
                                       retry_over_query_limit=False)
        self.gmaps_get_place_ID = googlemaps.Client(
            key=API_KEY, queries_per_second=50, retry_over_query_limit=False)
        self.google_places = GooglePlaces(API_KEY)

    def set_place_id(self, place, place_address):
        place.google_place_id = self.find_place_id(place_address)

    def find_place_id(self, place_address):
        result = self.gmaps_get_place_ID.find_place(input=place_address,
                                                    input_type='textquery')
        try:
            place_id = result['candidates'][0]['place_id']
        except IndexError:
            raise ValueError("Place not found")
        pp.pprint(result)
        return place_id

    def safe_index(self, place_detail, index):
        if index in place_detail:
            return place_detail[index]

    def set_store_detail(self, place):
        maps_place = self.google_places.get_place(place.google_place_id)
        maps_place.get_details()
        detail = maps_place.details
        print("-" * 50)
        pp.pprint(detail)
        if 'opening_hours' in detail and 'periods' in detail['opening_hours']:
            place.hours = detail['opening_hours']['periods']
        else:
            place.hours = 'NA'
        place.name = self.safe_index(detail, 'name')
        place.address = self.safe_index(detail, 'formatted_address')
        place.price_level = self.safe_index(detail, 'price_level')
        place.url = self.safe_index(detail, 'url')
        place.website = self.safe_index(detail, 'website')
        place.rating = self.safe_index(detail, 'rating')
        place.reviews = self.safe_index(detail, 'user_ratings_total')
        place.type_store = self.safe_index(detail, 'types')
        # place.save()

    def get_place_info(self, place, place_name):
        self.set_place_id(place, place_name)
        self.set_store_detail(place)

    def get_time(self, event, arrival_time):
        leg = None
        directions_result = None
        print('get_time event.start_address', event.start_address)
        print('get_time event.end_address', event.end_address)
        print('get_time arrival_time', arrival_time)  # try:
        directions_result = self.gmaps.directions(
            event.start_address,
            event.end_address,
            mode=self.TRAVEL_BY[event.travel_by],
            arrival_time=arrival_time)
        leg = directions_result[0]['legs'][0]
        # except IndexError or googlemaps.exceptions.ApiError:
        #     raise ValueError("No route")
        print(directions_result)
        event.start_address = leg['start_address']
        event.end_address = leg['end_address']
        print('get_time - event.save()')
        print('event.start_address', event.start_address)
        print('event.end_address', event.end_address)
        event.travel_distance = leg['distance']['value']  # in meter
        event.travel_duration = leg['duration']['value']  # in second
        print('event.travel_distance', event.travel_distance)
        print('event.travel_duration', event.travel_duration)
        event.save()
        print('event.travel_duration', event.travel_duration)
        return event
示例#10
0
from googleplaces import GooglePlaces, types, lang

YOUR_API_KEY = 'AIzaSyC1D8hoFRIH1Mw_YArJUK2VO9B9LSoxs24'

google_places = GooglePlaces(YOUR_API_KEY)

# You may prefer to use the text_search API, instead.
print google_places.get_place("ChIJ7z5P2ikbdkgRJbLXb5y1uWs")
# print query_result
# if query_result.has_attributions:
#     print query_result.html_attributions

# You may prefer to use the text_search API, instead.
query_result = google_places.nearby_search(
        location='London, England', keyword='Fish and Chips',
        radius=20000, types=[types.TYPE_FOOD])
print  query_result
if query_result.has_attributions:
    print query_result.html_attributions
    
for place in query_result.places:
    # Returned places from a query are place summaries.
    print place.name
    print place.geo_location
    print place.place_id
示例#11
0
文件: geoTest2.py 项目: jc3265/Places
print location
placeName = location.address.split(',')
print "Printing the name of the place: " + placeName[0]
'''
#Find distance between two points
#Start

#loc1 = (37.7528679,-122.4185353)
##loc2 = (37.7528804, -122.4185364)
#print(great_circle(loc1, loc2).kilometers)
#End

#ChIJCVOWkMeAhYARS9aj9GhYuc8,ChIJ8aZslMeAhYARk2BJNvkVPyc,ChIJr3AblMeAhYARrtrGjPRtH3k


l =google_places.get_place(place_id = 'ChIJ6TRCEUN-j4ARj2bdLZOgsLA')
printable = set(string.printable)
print (filter(lambda x: x in printable, l.name))

#print l.name
#placeName2 = str(l.name.replace("\xce", "n"))
#print placeName2
#try:
#    placeName1 = str(l.name.replace(",", ""))
#except:
    #print "SDSDSD"
    #name = l.name
    #print "dfsdfsdfsd"
#    place = l.name[:-1]
    #print place
#print l.name.split("\\")[0].split("\\x")
示例#12
0
def add_place(place_id):
    API_KEY = "AIzaSyBM7aOj21cM0LyY07I0EDBSpTNwFrYxlfU"

    google = GooglePlaces(API_KEY)

    place_details = google.get_place(place_id=place_id)

    # There is a chance the Places API produces an index error if some components are missing
    # With the formatted address we do our best to find those missing parts if we encounter it
    # We expect the formatted address to look like this; 1234 Foo Ln, FooBar, NJ 08005, USA
    formatted_addr = place_details.details['formatted_address'].strip(
        " ").split(",")

    try:
        # Street Addr from google Places API
        addr = place_details.details['address_components'][0]['long_name'] + " " + \
               place_details.details['address_components'][1]['long_name']

        # City from google Places API
        addr_city = place_details.details['address_components'][2][
            'short_name']

        # State short name 'XX' from google places API
        addr_state = place_details.details['address_components'][5][
            'short_name']

        # Zip code from places API
        addr_zip = place_details.details['address_components'][7]['long_name']

        # Country from google places API
        addr_country = place_details.details['address_components'][6][
            'short_name']

    # If we have an index error are indices are wrong so we need to use the formatted address
    except IndexError:
        addr = formatted_addr[0]
        addr_city = formatted_addr[1].strip()
        addr_state = formatted_addr[2][1:3].strip()
        addr_zip = formatted_addr[2][4:9].strip()
        addr_country = formatted_addr[3]

    # International formatted phone number from google places API
    phone_inter = place_details.details['international_phone_number']

    # Franchise name from google places API
    place_name = place_details.details['name']

    new_place = Place(
        gid=
        place_id,  # The place ID in this case would be a Google Places Reference ID
        name=place_name,
        phone=phone_inter,  # TODO fix this need to DB
        address=addr,
        address_city=addr_city,
        address_state=addr_state,
        address_zip=addr_zip,
        address_country=addr_country)
    # TODO add try/except block for errors
    db.session.add(new_place)
    db.session.commit()
    return new_place
示例#13
0
def app_context():
    with app.app_context():
        query = Place.query.filter_by()
        for x in query:
            print(x.name)

        # Google API Key for places
        API_KEY = "AIzaSyBM7aOj21cM0LyY07I0EDBSpTNwFrYxlfU"

        google = GooglePlaces(API_KEY)

        # Try adding a new place.. ?
        place_id = 'ChIJn8ORMaIIwYkRDjaLeuBXyN8'
        place_details = google.get_place(place_id=place_id)
        # print(place_details.details)

        # Street Addr from google Places API
        addr = place_details.details['address_components'][0]['long_name'] + " " + \
               place_details.details['address_components'][1]['long_name']
        print(addr)

        # City from google Places API
        addr_city = place_details.details['address_components'][2][
            'short_name']
        print(addr_city)

        # State short name 'XX' from google places API
        addr_state = place_details.details['address_components'][5][
            'short_name']
        print(addr_state)

        # Zip code from places API
        addr_zip = place_details.details['address_components'][7]['long_name']
        print(addr_zip)

        # Country from google places API
        addr_country = place_details.details['address_components'][6][
            'short_name']
        print(addr_country)

        # International formatted phone number from google places API
        phone_inter = place_details.details['international_phone_number']
        print(phone_inter)

        # Franchise name from google places API
        place_name = place_details.details['name']
        print(place_name)

        new_place = Place(
            gid=
            place_id,  # The place ID in this case would be a Google Places Reference ID
            name=place_name,
            phone1="test",
            address=addr,
            address_city=addr_city,
            address_state=addr_state,
            address_zip=addr_zip,
            address_country=addr_country)
        # TODO add try/except block for errors
        print('test1')
        db.session.add(new_place)
        db.session.commit()
示例#14
0
文件: places.py 项目: envizzion/banna
    # keyword='general',
    # types =[types.TYPE_HOSPITAL] or
    # [types.TYPE_CAFE] or [type.TYPE_BAR]
    # or [type.TYPE_CASINO])
    type=types.TYPE_POLICE)

# If any attributions related
# with search results print them
if query_result.has_attributions:
    print(query_result.html_attributions)

placeID = ""
# Iterate over the search results
for place in query_result.places:
    # print(type(place))
    # place.get_details()
    print(place.name)
    print("Latitude", place.geo_location['lat'])
    print("Longitude", place.geo_location['lng'])
    placeID = place.place_id
    print("id:", placeID)
    # place.get_details()
    # print(place)
    print()
    break

query_result2 = google_places.get_place(place_id=placeID, )

if query_result2.has_attributions:
    print(query_result2.html_attributions)
示例#15
0
class GoogleMapsProcessor(object):
    def __init__(self):
        self.google_places = GooglePlaces(settings.MAPS_API_KEY)

    def search(self, keyword, latlng):
        """
		Search Google Places for Businesses
		"""
        # You may prefer to use the text_search API, instead.

        search_tokens = keyword.split(' ')

        response = []
        for token in search_tokens:
            query_result = self.google_places.nearby_search(
                lat_lng=latlng,
                keyword=token,
                radius=10000,
                types=[
                    types.TYPE_AMUSEMENT_PARK,
                    types.TYPE_BAKERY,
                    types.TYPE_BAR,
                    types.TYPE_BOOK_STORE,
                    types.TYPE_CAFE,
                    types.TYPE_CLOTHING_STORE,
                    types.TYPE_CONVENIENCE_STORE,
                    types.TYPE_DEPARTMENT_STORE,
                    types.TYPE_FOOD,
                    types.TYPE_GROCERY_OR_SUPERMARKET,
                    types.TYPE_HARDWARE_STORE,
                    types.TYPE_HEALTH,
                    types.TYPE_HOME_GOODS_STORE,
                    types.TYPE_LIBRARY,
                    types.TYPE_LIQUOR_STORE,
                    types.TYPE_MEAL_DELIVERY,
                    types.TYPE_MEAL_TAKEAWAY,
                    types.TYPE_MOVIE_THEATER,
                    types.TYPE_MUSEUM,
                    types.TYPE_NIGHT_CLUB,
                    types.TYPE_PARK,
                    types.TYPE_PHARMACY,
                    types.TYPE_RESTAURANT,
                    types.TYPE_SHOE_STORE,
                    types.TYPE_SHOPPING_MALL,
                    types.TYPE_STORE,
                ])

            for place in query_result.places:
                # Returned places from a query are place summaries.
                cache = {}
                place.get_details()
                cache['id'] = place.place_id
                cache['name'] = place.name
                cache['address'] = place.formatted_address
                cache['website'] = place.website
                cache['phone'] = place.local_phone_number
                cache['lat'] = float(place.geo_location.get('lat'))
                cache['lng'] = float(place.geo_location.get('lng'))
                cache['rating'] = place.rating
                cache['types'] = place.types[0] if len(
                    place.types) > 0 else 'Others'

                for photo in place.photos:
                    photo.get(maxheight=800, maxwidth=533)
                    cache['photo'] = photo.url
                    break

                response.append(cache)

        return response
        """
		Search Expedia Hotels
		"""

    def search_by_text(self, name, lat, lng):

        latlng = {'lat': lat, 'lng': lng}

        query_result = self.google_places.text_search(
            lat_lng=latlng,
            query=name,
            radius=10,
            types=[
                types.TYPE_AMUSEMENT_PARK,
                types.TYPE_BAKERY,
                types.TYPE_BAR,
                types.TYPE_BOOK_STORE,
                types.TYPE_CAFE,
                types.TYPE_CLOTHING_STORE,
                types.TYPE_CONVENIENCE_STORE,
                types.TYPE_DEPARTMENT_STORE,
                types.TYPE_FOOD,
                types.TYPE_GROCERY_OR_SUPERMARKET,
                types.TYPE_HARDWARE_STORE,
                types.TYPE_HEALTH,
                types.TYPE_HOME_GOODS_STORE,
                types.TYPE_LIBRARY,
                types.TYPE_LIQUOR_STORE,
                types.TYPE_MEAL_DELIVERY,
                types.TYPE_MEAL_TAKEAWAY,
                types.TYPE_MOVIE_THEATER,
                types.TYPE_MUSEUM,
                types.TYPE_NIGHT_CLUB,
                types.TYPE_PARK,
                types.TYPE_PHARMACY,
                types.TYPE_RESTAURANT,
                types.TYPE_SHOE_STORE,
                types.TYPE_SHOPPING_MALL,
                types.TYPE_STORE,
            ])

        return query_result

    def get_place(self, place_id):

        place = self.google_places.get_place(place_id)
        cache = {}
        place.get_details()
        details = place.details
        detail_keys = details.keys()

        # Get Reviews
        cache['reviews'] = []
        if 'reviews' in detail_keys:
            result = []
            for review in details['reviews']:
                cache = {}
                cache['rating'] = review.get('rating')
                cache['rating_range'] = range(int(
                    review.get('rating'))) if review.get('rating') else 0
                cache['photo'] = review.get('profile_photo_url')
                cache['text'] = review.get('text')
                cache['name'] = review.get('author_name')
                cache['time'] = review.get('time')
                result.append(cache)

            cache['reviews'] = result
        cache['review_count'] = len(cache['reviews'])
        cache['id'] = place.place_id
        cache['name'] = place.name
        cache['address'] = place.formatted_address
        cache['website'] = place.website
        cache['phone'] = place.local_phone_number
        cache['vicinity'] = place.vicinity
        cache['lat'] = float(place.geo_location.get('lat'))
        cache['lng'] = float(place.geo_location.get('lng'))
        cache['rating'] = place.rating
        cache['rating_range'] = range(int(place.rating)) if place.rating else 0
        cache['types'] = place.types[0] if len(place.types) > 0 else 'Others'
        cache['photos'] = []

        for photo in place.photos:
            photo.get(maxheight=1400, maxwidth=470)
            cache['banner'] = photo.url
            break

        for photo in place.photos:

            photo.get(maxheight=800, maxwidth=533)
            cache['photos'].append(photo.url)

        return cache
示例#16
0
import webbrowser
import requests
import json
from openpyxl import Workbook

# ChIJm5MaboqXyzsR-xPxquRpWss

API_KEY = 'AIzaSyBGBT5ghLBk8nGYDxf6RfMxuNb8P7ojnDg'
from googleplaces import GooglePlaces, types, lang

google_places = GooglePlaces(API_KEY)
pid = input("Enter Place ID: ")
xmlfile = google_places.get_place(place_id=pid)
url = "https://maps.googleapis.com/maps/api/place/details/json?place_id=" + pid + "&fields=name,rating,review&key=" + API_KEY

# webbrowser.open_new(url=url)

response = requests.get(url)
with open('main.json', 'wb') as file:
    file.write(response.content)

with open('main.json', 'rb') as file:
    string = json.load(file)
webpage = string["result"]
reviews = string["result"]["reviews"]

name = string["result"]["name"]
rating = string["result"]["rating"]

workbook = Workbook()
sheet = workbook.active
示例#17
0
from googleplaces import GooglePlaces, types, lang
import googlemaps

YOUR_API_KEY = 'AIzaSyC9a-jaBIbXokxx9dIz7aTP9jbOjLCC9ag'
gmaps = googlemaps.Client(key='AIzaSyC9a-jaBIbXokxx9dIz7aTP9jbOjLCC9ag')

google_places = GooglePlaces(YOUR_API_KEY)

print(
    google_places.get_place(
        place_id=
        'qgYvCi0wMDAwMDBjNmVlMjk0ZDM0OjQwYzdlZGFiNjQzOmZlZmZhOWMyNzMzZDUwMzI'))

#google_places.delete_place(place_id='qgYvCi0wMDAwMDBjNmVlMjk0ZDM0OjQwZDRjZTgyYWFmOjRmZDhlMDg4YTc5NTE1MGM')
示例#18
0
        # set default values
        place = 'ABC123'
        google_places_array.at[i, 'lat'] = -1
        google_places_array.at[i, 'long'] = -1
        google_places_array.at[i, 'type'] = 'XXXXX'
        google_places_array.at[i, 'rating'] = -1
        # print(addr)
        # print(geocode_result[0]['geometry']['location']['lat'])
        # print(geocode_result[0]['geometry']['location']['lng'])
        try:
            addr = google_places_array.fulladdress[i]
            geocode_result = gmaps.geocode(addr)

            place = geocode_result[0]['place_id']  # need to trap this error
            query_result = google_places.get_place(place_id=place)
            query_result.get_details()
            #print (query_result.types)
            google_places_array.at[
                i, 'lat'] = geocode_result[0]['geometry']['location']['lat']
            google_places_array.at[
                i, 'long'] = geocode_result[0]['geometry']['location']['lng']
            google_places_array.at[i, 'type'] = query_result.types
            google_places_array.at[i, 'rating'] = query_result.rating
        #print('detail name')
        #print (query_result.name)
        # print(query_result.rating)
        # print('\r')
        except:
            print("An error")
            print(counter)