Пример #1
0
func (p *Proximity) Search(p0, p1 s2.LatLng) []s2.CellID {
	boundRect := s2.RectFromLatLng(p0)
	boundRect = boundRect.AddPoint(p1)

	startToken := []byte(s2.CellIDFromLatLng(boundRect.Hi()).ToToken())
	endToken := []byte(s2.CellIDFromLatLng(boundRect.Lo()).ToToken())

	results := []s2.CellID{}
	p.DB.View(func(tx *bolt.Tx) error {
		cursor := tx.Bucket([]byte("proximity")).Cursor()
		for k, _ := cursor.Seek(startToken); k != nil && bytes.Compare(k, endToken) <= 0; k, _ = cursor.Next() {
			cell := s2.CellIDFromToken(string(k))
			results = append(results, cell)
		}
		return nil
	})
	return results
}
Пример #2
0
func (p *Proximity) Match(p0, p1 s2.LatLng) bool {
	boundRect := s2.RectFromLatLng(p0)
	boundRect = boundRect.AddPoint(p1)

	startToken := []byte(s2.CellIDFromLatLng(boundRect.Hi()).ToToken())
	endToken := []byte(s2.CellIDFromLatLng(boundRect.Lo()).ToToken())

	found := false
	p.DB.View(func(tx *bolt.Tx) error {
		cursor := tx.Bucket([]byte("proximity")).Cursor()
		for k, _ := cursor.Seek(startToken); k != nil && bytes.Compare(k, endToken) <= 0; k, _ = cursor.Next() {
			found = true
			break
		}
		return nil
	})
	return found
}