def test_is_valid_lat(self):
        self.failUnless(is_valid_lat(90))
        self.failUnless(is_valid_lat(90.0))
        self.failUnless(is_valid_lat(D('90.0')))
        self.failUnless(is_valid_lat(-90))
        self.failUnless(is_valid_lat(-90.0))
        self.failUnless(is_valid_lat(D('-90.0')))

        self.failIf(is_valid_lat(90.0002))
        self.failIf(is_valid_lat(D('90.0002')))
        self.failIf(is_valid_lat(-90.0002))
        self.failIf(is_valid_lat(D('-90.0002')))
    def search(self, lat, lon, radius=None, query=None, category=None):
        """Search for places near a lat/lon, within a radius (in kilometers)."""
        precondition(is_valid_lat(lat), lat)
        precondition(is_valid_lon(lon), lon)
        precondition(radius is None or is_numeric(radius), radius)
        precondition(query is None or isinstance(query, basestring), query)
        precondition(category is None or isinstance(category, basestring), category)

        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
        quargs = urllib.urlencode(kwargs)
        if quargs:
            quargs = '?'+quargs
        endpoint = self._endpoint('search', lat=lat, lon=lon, quargs=quargs)

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

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc['features']]
 def get_context_async(self, lat, lon, **kwds):
     """
     Starts an asynchronous request using GAE's URL Fetch service.
     Returns an RPC object that can be subsequently passed to get_context_result()
     
     **kwds
         Keyword arguments to pass when creating the RPC object.
         See http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html#create_rpc
     """
     
     rpc = urlfetch.create_rpc(**kwds)
     precondition(is_valid_lat(lat), lat)
     precondition(is_valid_lon(lon), lon)
     endpoint = self._endpoint('context', lat=lat, lon=lon)
     headers = self._headers(endpoint, 'GET')
     urlfetch.make_fetch_call(rpc, endpoint, headers=headers)
     return rpc
    def search(self, lat, lon, radius=None, query=None, category=None):
        """Search for places near a lat/lon."""
        precondition(is_valid_lat(lat), lat)
        precondition(is_valid_lon(lon), lon)
        precondition(radius is None or is_numeric(radius), radius)
        precondition(query is None or isinstance(query, basestring), query)
        precondition(category is None or isinstance(category, basestring), category)

        kwargs = {}
        if radius:
            kwargs["radius"] = radius
        if query:
            kwargs["q"] = query
        if category:
            kwargs["category"] = category
        quargs = urllib.urlencode(kwargs)
        if quargs:
            quargs = "?" + quargs
        endpoint = self._endpoint("search", lat=lat, lon=lon, quargs=quargs)

        result = self._request(endpoint, "GET")[1]

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc["features"]]
 def get_context(self, lat, lon):
     precondition(is_valid_lat(lat), lat)
     precondition(is_valid_lon(lon), lon)
     endpoint = self._endpoint('context', lat=lat, lon=lon)
     return json_decode(self._request(endpoint, "GET")[1])