예제 #1
0
    def search(self, lat, lon, radius=None, query=None, category=None, num=None):
        """Search for places near a lat/lon, within a radius (in kilometers)."""
        _assert_valid_lat(lat)
        _assert_valid_lon(lon)
        if (radius and not is_numeric(radius)):
            raise ValueError("Radius must be numeric.")
        if (query and not isinstance(query, basestring)):
            raise ValueError("Query must be a string.")
        if (category and not isinstance(category, basestring)):
            raise ValueError("Category must be a string.")
        if (num and not is_numeric(num)):
            raise ValueError("Num parameter must be numeric.")

        if isinstance(query, unicode):
            query = query.encode('utf-8')
        if isinstance(category, unicode):
            category = category.encode('utf-8')

        kwargs = { }
        if radius:
            kwargs['radius'] = radius
        if query:
            kwargs['q'] = query
        if category:
            kwargs['category'] = category
        if num:
            kwargs['num'] = num

        endpoint = self._endpoint('search', lat=lat, lon=lon)

        result = self._request(endpoint, 'GET', data=kwargs)[1]

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc['features']]
예제 #2
0
    def search_bbox(self, lat_sw, lon_sw, lat_ne, lon_ne, query=None,
                    category=None, limit=None, start=None):
        """Return places inside a box of (lat_sw, lon_sw), (lat_ne, lon_ne)."""
        _assert_valid_lat(lat_sw)
        _assert_valid_lat(lat_ne)
        _assert_valid_lon(lon_sw)
        _assert_valid_lon(lon_ne)
        if (query and not isinstance(query, basestring)):
            raise ValueError("Query must be a string.")
        if (category and not isinstance(category, basestring)):
            raise ValueError("Category must be a string.")
        if (limit and not is_numeric(limit)):
            raise ValueError("Limit parameter must be numeric.")
        if (start and not is_numeric(start)):
            raise ValueError("Start parameter must be numeric.")

        if isinstance(query, unicode):
            query = query.encode('utf-8')
        if isinstance(category, unicode):
            category = category.encode('utf-8')

        kwargs = { }
        if query:
            kwargs['q'] = query
        if category:
            kwargs['category'] = category
        if limit:
            kwargs['limit'] = limit
        if start:
            kwargs['start'] = start

        return self._respond(*self._request(self._endpoint(
                    'search_bbox', lat_sw=lat_sw, lon_sw=lon_sw,
                    lat_ne=lat_ne, lon_ne=lon_ne), 'GET', data=kwargs))
예제 #3
0
    def get_context(self, lat, lon, filter=None, context_args=None):
        _assert_valid_lat(lat)
        _assert_valid_lon(lon)

        if filter and not isinstance(filter, basestring):
            raise ValueError("Query must be a string.")

        kwargs = self._prepare_kwargs(filter=filter, context_args=context_args)

        endpoint = self._endpoint("context", lat=lat, lon=lon)
        result = self._request(endpoint, "GET", data=kwargs)[1]
        return json_decode(result)
예제 #4
0
    def get_context(self, lat, lon, filter=None):
        _assert_valid_lat(lat)
        _assert_valid_lon(lon)

        if (filter and not isinstance(filter, basestring)):
            raise ValueError("Query must be a string.")

        kwargs = { }
        if filter:
            kwargs['filter'] = filter

        endpoint = self._endpoint('context', lat=lat, lon=lon)
        result = self._request(endpoint, 'GET', data=kwargs)[1]
        return json_decode(result)
예제 #5
0
    def search(self, lat, lon, radius=None, query=None, category=None,
               limit=None, start=None):
        """Search for places near a lat/lon, within a radius (in kilometers)."""
        _assert_valid_lat(lat)
        _assert_valid_lon(lon)
        if (radius and not is_numeric(radius)):
            raise ValueError("Radius must be numeric.")
        if (query and not isinstance(query, basestring)):
            raise ValueError("Query must be a string.")
        if (category and not isinstance(category, basestring)):
            raise ValueError("Category must be a string.")
        if (limit and not is_numeric(limit)):
            raise ValueError("Limit parameter must be numeric.")
        if (start and not is_numeric(start)):
            raise ValueError("Start parameter must be numeric.")

        if isinstance(query, unicode):
            query = query.encode('utf-8')
        if isinstance(category, unicode):
            category = category.encode('utf-8')

        kwargs = { }
        if radius:
            kwargs['radius'] = radius
        if query:
            kwargs['q'] = query
        if category:
            kwargs['category'] = category
        if limit:
            kwargs['limit'] = limit
        if start:
            kwargs['start'] = start

        return self._respond(*self._request(self._endpoint(
                    'search', lat=lat, lon=lon),
                              'GET', data=kwargs))