s2-geometry-library-csharp icon indicating copy to clipboard operation
s2-geometry-library-csharp copied to clipboard

Getting S2 Cell ID for specific position and level

Open VampireSilence opened this issue 5 years ago • 2 comments

I am trying to get the level 10 cell ID for central Manchester.

Google says its coordinate is 53.479683, -2.242776. So i tried it like that: S2LatLng ll = S2LatLng.FromDegrees(53.479683, -2.242776); But now if i try to get the ID like this: S2CellId.FromLatLng(ll).Id.ToString(); It returns the wrong cell ID and S2CellId.FromLatLng(ll).Level is always level 30 without any chance of choosing it. How can i set the S2 cell level i like and get the right cell ID?

VampireSilence avatar Feb 07 '20 19:02 VampireSilence

I too am wanting to achieve this.

mahgo avatar Feb 17 '20 05:02 mahgo

@VampireSilence Here's how I achieved it:

S2LatLng s2LatLng = S2LatLng.FromDegrees(latitude, longitude); S2Cell s2Cell = new S2Cell(s2LatLng); S2CellId s2CellId = s2Cell.Id; S2CellId s2Cell11Id = s2CellId.ParentForLevel(11);

mahgo avatar Feb 17 '20 21:02 mahgo