예제 #1
0
 def getEntityAutocompleteResults(self, query, latLng=None, params=None, priority='low'):
     results = self.getAutocompleteResults(latLng, query, params, priority)
     output  = []
     
     if results is not None:
         for result in results:
             entity = PlaceEntity()
             
             entity.sources.googleplaces_id        = result['id']
             entity.sources.googleplaces_reference = result['reference']
             
             try:
                 terms = result['terms']
                 entity.title = terms[0]['value']
                 
                 if len(terms) > 1:
                     if terms[-1]['value'] == "United States":
                         terms = terms[:-1]
                     
                     entity.formatted_address = string.joinfields((v['value'] for v in terms[1:]), ', ')
             except:
                 entity.title = result['description']
             
             output.append(entity)
     
     return output
예제 #2
0
 def parseEntity(self, result, valid=False):
     subcategory  = self.getSubcategoryFromTypes(result['types'])
     if not valid and subcategory not in self.google_subcategory_whitelist:
         return None
     
     entity                                  = PlaceEntity()
     entity.title                            = result['name']
     coordinates                             = Coordinates()
     coordinates.lat                         = result['geometry']['location']['lat']
     coordinates.lng                         = result['geometry']['location']['lng']
     entity.coordinates                      = coordinates
     entity.sources.googleplaces_id          = result['id']
     entity.sources.googleplaces_reference   = result['reference']
     
     # TODO: TYPE
     types = set(entity.types)
     types.add(subcategory)
     entity.types = list(types)
     
     """
     if result['icon'] != u'http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png' and \
        result['icon'] != u'http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png':
         entity.image = result['icon']
     """
     
     if 'vicinity' in result:
         entity.neighborhood = result['vicinity']
     
     return entity