Skip to content

Instantly share code, notes, and snippets.

@zeeshangtk
Created February 13, 2018 05:12
Show Gist options
  • Save zeeshangtk/752f45448ae7478b1986983aa2fc901c to your computer and use it in GitHub Desktop.
Save zeeshangtk/752f45448ae7478b1986983aa2fc901c to your computer and use it in GitHub Desktop.
Validate the location using s2 ids
package main
import (
"strings"
"github.com/golang/geo/s2"
)
func main() {
// we got s2 ids from https://s2.sidewalklabs.com/regioncoverer/
cellIDs := strings.Split("3a3154,3a315c,3a3164,3a317d,3a334,3a33c,3a344,3a34c,3a351,3a3524,3a352c,3a35b,3a35d,3a3677,3a367c,3a3684,3a369c,3a36a4,3a36ac,3bc90c,3bc914,3bc934,3bc93c,3bc95,3bc97,3bc984,3bc99c,3bc9a1,3bca2c,3bca34,3bca4c,3bca54,3bcad4,3bcadc,3bcae4,3bcafc,3bcb4,3bcbc,3bcc4,3bccc,3bcdad,3bcdb4,3bcdcc,3bcdd4,3bce5f,3bce64,3bce7c,3bce9,3bceb,3bcec4,3bcecc,3bceec,3bcef4", ",")
println("_______________________")
for _, cellID := range cellIDs {
//this input cell should be part of one of the s2ids
inputCell := s2.CellFromLatLng(s2.LatLngFromDegrees(17.4126274, 78.2679595))
cell := s2.CellFromCellID(s2.CellIDFromToken(cellID))
yes := cell.ContainsCell(inputCell)
println(cellID, yes)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment