Beispiel #1
0
 def get(self):
     self.response.out.write('hello<br/>')
     brom = Neighborhood.gql("WHERE name = :1", "b_woods").get()
     card = Neighborhood.gql("WHERE name = :1", "card").get()
     distance = geomath.distance(brom.location,
                                 card.location) * 0.000621371192
     self.response.out.write("%.2f miles" % distance)
Beispiel #2
0
    def test_distance(self):
        # known distances using GLatLng from the Maps API
        calc_dist = geomath.distance(geotypes.Point(37, -122),
                                     geotypes.Point(42, -75))
        known_dist = 4024365

        # make sure the calculated distance is within +/- 1% of known distance
        self.assertTrue(abs((calc_dist - known_dist) / known_dist) <= 0.01)
Beispiel #3
0
  def test_distance(self):
    # known distances using GLatLng from the Maps API
    calc_dist = geomath.distance(geotypes.Point(37, -122),
                                 geotypes.Point(42, -75))
    known_dist = 4024365

    # make sure the calculated distance is within +/- 1% of known distance
    self.assertTrue(abs((calc_dist - known_dist) / known_dist) <= 0.01)
Beispiel #4
0
    def get(self):
        try:
            latitude = float(self.request.get('lat'))
            longitude = float(self.request.get('lng'))
            list_search_against = int(self.request.get('list'))
            radius = int(self.request.get('radius', 2500)) # 2.5 km by default
            max_results = int(self.request.get('max_results', 100))
            max_price = int(self.request.get('max_price', 0))
        except ValueError:
            return self._error('INVALID_PARAMETERS', 400) # Bad request

        approx_results = self.request.get('approx', False)

        if not latitude or not longitude or not list_search_against:
            return self._error('INVALID_PARAMETERS', 400) # Bad request

        list_key = List.get_by_id(list_search_against).key()
        query = Post.all().filter('posted_list =', list_key).order('-created')
        if not approx_results:
            query = query.filter('approx_geolocation =', False)

        center = geotypes.Point(latitude, longitude)

        proximity_posts = Post.proximity_fetch(
            query,
            center,
            max_results=max_results,
            max_distance=radius
        )

        self.response.headers['Content-Type'] = 'application/json'
        if proximity_posts:
            results = [{'title': post.title,
                        'price': post.price,
                        'location': [post.latitude, post.longitude],
                        'id': post.key().id(),
                        'distance': round(geomath.distance(center,
                            geotypes.Point(post.latitude, post.longitude))),
                        'created': post.created.ctime(),
                       } for post in proximity_posts]

            return self.response.out.write(json.dumps({
                'status': 'OK',
                'count': len(results),
                'center': [latitude, longitude],
                'results': results
            }))
        else:
            return self.response.out.write(json.dumps({
                'status': 'OK',
                'count': 0,
                'center': [latitude, longitude],
                'results': []
            }))
import webapp2
Beispiel #6
0
 def in_radius(self, reqHandler):
     distance = geomath.distance(db.GeoPt(self.loc), db.GeoPt("%s,%s"%(reqHandler['lat'], reqHandler['lon'])))
     radius = float(reqHandler['radius'])
     return True if distance < radius else False
Beispiel #7
0
import webapp2
Beispiel #8
0
 def get(self):
     self.response.out.write('hello<br/>')
     brom = Neighborhood.gql("WHERE name = :1", "b_woods").get()
     card = Neighborhood.gql("WHERE name = :1", "card").get()
     distance = geomath.distance(brom.location, card.location) * 0.000621371192
     self.response.out.write("%.2f miles" % distance)
Beispiel #9
0
 def in_radius(self, reqHandler):
     distance = geomath.distance(
         db.GeoPt(self.loc),
         db.GeoPt("%s,%s" % (reqHandler['lat'], reqHandler['lon'])))
     radius = float(reqHandler['radius'])
     return True if distance < radius else False