code: def infer_location(
          point,
          location_query,
          max_distance,
          google_key,
          foursquare_client_id,
          foursquare_client_secret,
          limit
      ):
      
      locations = []
  
      if location_query is not None:
          queried_locations = location_query(point, max_distance)
          for (label, centroid, _) in queried_locations:
              locations.append({
                  'label': unicode(label, 'utf-8'),
                  'distance': centroid.distance(point),
                  # 'centroid': centroid,
                  'suggestion_type': 'KB'
                  })
  
      api_locations = []
      if len(locations) <= limit:
          if google_key:
              google_locs = query_google(point, max_distance, google_key)
              api_locations.extend(google_locs)
          if foursquare_client_id and foursquare_client_secret:
              foursquare_locs = query_foursquare(
                  point,
                  max_distance,
                  foursquare_client_id,
                  foursquare_client_secret
              )
              api_locations.extend(foursquare_locs)
  
      if len(locations) > 0 or len(api_locations) > 0:
          locations = sorted(locations, key=lambda d: d['distance'])
          api_locations = sorted(api_locations, key=lambda d: d['distance'])
          locations = (locations + api_locations)[:limit]
          return Location(locations[0]['label'], point, locations)
      else:
          return Location('#?', point, [])
docs: Infers the semantic location of a (point) place.
  
      Args:
          points (:obj:`Point`): Point location to infer
          location_query: Function with signature, (:obj:`Point`, int) -> (str, :obj:`Point`, ...)
          max_distance (float): Max distance to a position, in meters
          google_key (str): Valid google maps api key
          foursquare_client_id (str): Valid Foursquare client id
          foursquare_client_secret (str): Valid Foursquare client secret
          limit (int): Results limit
      Returns:
          :obj:`Location`: with top match, and alternatives