Closed PanicIsReal closed 8 years ago
Sorry, I don't know anything about that node package. Can you state exactly what you're trying to get from the s2.CellID
?
Hi thanks for the reply. I'm not sure to be honest I'm trying to port over something from Node to Go, there's a small part that looks like this:
function getNeighbors(lat, lng) {
var origin = new s2.S2CellId(new s2.S2LatLng(lat, lng)).parent(15);
var walk = [origin.id()];
// 10 before and 10 after
var next = origin.next();
var prev = origin.prev();
for (var i = 0; i < 10; i++) {
// in range(10):
walk.push(prev.id());
walk.push(next.id());
next = next.next();
prev = prev.prev();
}
return walk;
}
Which my go code looks like
func GetNeighbors(location *Location) [][]byte {
ll := s2.LatLngFromDegrees(location.Latitude, location.Longitude)
cid := s2.CellIDFromLatLng(ll).Parent(15)
walkDataUnsorted := []uint64{cid.Pos()}
next := cid.Next()
prev := cid.Prev()
for i := 0; i < 10; i++ {
walkDataUnsorted = append(walkDataUnsorted, next.Pos())
walkDataUnsorted = append(walkDataUnsorted, prev.Pos())
next = next.Next()
prev = prev.Prev()
}
UInts(walkDataUnsorted)
buffy := new(bytes.Buffer)
for _, num := range walkDataUnsorted {
binary.Write(buffy, binary.LittleEndian, num)
}
return [][]byte{buffy.Bytes()}
}
I don't know anything about s2 geo I'm just trying to recreate this very small function but I'm getting a different result
The id() from the node package gives me a uint64 starting with the number 6
The pos() gives me a uint64 starting with the number 1 On Sun, Jul 24, 2016 at 4:18 AM David Symonds notifications@github.com wrote:
Sorry, I don't know anything about that node package. Can you state exactly what you're trying to get from the s2.CellID?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/golang/geo/issues/12#issuecomment-234769125, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTlMqp2IkTfEXee8Mtc3jXUgL-FAKDrks5qYzv_gaJpZM4JThSl .
Looks like doing uint64(cid)
gives me the numbers I'm looking for. Thanks.
I'm trying to use this package for a project over
s2geometry-node
Which has this:
Which does this: https://github.com/billyriantono/s2geometry-node/blob/master/API.md#cellidid---number
I'm trying to achieve similar results by doing: