### Get All Neighboring Geohashes with Geohash.Neighbors Struct Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt A struct containing all eight neighboring geohashes with named properties. Provides convenience methods for working with neighbor sets, including the center cell. ```swift import FlitsGeohash let hash = "gcpvj" // London area let neighbors: Geohash.Neighbors = Geohash.neighbors(hash: hash) // Direct property access for each of the 8 neighbors let cardinalDirections = [ "N": neighbors.north, "S": neighbors.south, "E": neighbors.east, "W": neighbors.west ] let diagonalDirections = [ "NE": neighbors.northEast, "NW": neighbors.northWest, "SE": neighbors.southEast, "SW": neighbors.southWest ] // allNeighbors returns Set of all 8 neighbors let neighborSet: Set = neighbors.allNeighbors print("Unique neighbors: \(neighborSet.count)") // 8 // allNeighbors(and:) includes the center cell (9-cell grid) let fullGrid: Set = neighbors.allNeighbors(and: hash) print("Full grid cells: \(fullGrid.count)") // 9 // Practical use: Check if two geohashes are adjacent func areAdjacent(_ hash1: String, _ hash2: String) -> Bool { return Geohash.neighbors(hash: hash1).allNeighbors.contains(hash2) } print(areAdjacent("gcpvj", neighbors.north)) // true print(areAdjacent("gcpvj", "u4pru")) // false ``` -------------------------------- ### Get Neighbors of a Geohash Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Retrieves all eight neighboring geohashes for a given geohash string. Includes helpers to access neighbors by direction or as a set, and to include the center cell. ```swift import FlitsGeohash let hash = "u4pruydqqvj" let neighbors = Geohash.neighbors(hash: hash) // Access individual neighbors print("North: \(neighbors.north)") // "u4pruydqqvm" print("South: \(neighbors.south)") // "u4pruydqquv" print("East: \(neighbors.east)") // "u4pruydqqvn" print("West: \(neighbors.west)") // "u4pruydqqvh" print("NorthEast: \(neighbors.northEast)") // "u4pruydqqvq" print("NorthWest: \(neighbors.northWest)") // "u4pruydqqvk" print("SouthEast: \(neighbors.southEast)") // "u4pruydqquy" print("SouthWest: \(neighbors.southWest)") // "u4pruydqquu" // Get all neighbors as a Set for spatial queries let allNeighbors = neighbors.allNeighbors print("Neighbor count: \(allNeighbors.count)") // 8 // Get neighbors including the center cell (9-cell grid) let gridCells = neighbors.allNeighbors(and: hash) print("Grid cell count: \(gridCells.count)") // 9 // Use for proximity search - check if a point is near the center func isNearby(geohash: String, center: String) -> Bool { let neighbors = Geohash.neighbors(hash: center) return neighbors.allNeighbors(and: center).contains(geohash) } print(isNearby(geohash: "u4pruydqqvm", center: hash)) // true (north neighbor) print(isNearby(geohash: "u4pruydqqxx", center: hash)) // false (not adjacent) ``` -------------------------------- ### Get Adjacent Geohashes Source: https://github.com/flitsmeister/flitsgeohash/blob/main/README.md Retrieve the geohash for an adjacent cell in a cardinal direction (north, south, east, west) or all 8 neighboring cells. ```swift let hash = "u4pruydqqvj" let north = Geohash.adjacent(hash: hash, direction: .north) // "u4pruydqqvm" let neighbors = Geohash.neighbors(hash: hash) print(neighbors.east) // "u4pruydqqvn" print(neighbors.southWest) // "u4pruydqquu" print(neighbors.allNeighbors) ``` -------------------------------- ### Run Swift Tests Source: https://github.com/flitsmeister/flitsgeohash/blob/main/CONTRIBUTING.md Before submitting a pull request, ensure all tests pass by running this command in your terminal. ```bash swift test ``` -------------------------------- ### Add FlitsGeohash Product to Target Source: https://github.com/flitsmeister/flitsgeohash/blob/main/README.md Include the FlitsGeohash product in your target's dependencies in Package.swift. ```swift targets: [ .target( name: "YourTarget", dependencies: [ .product(name: "FlitsGeohash", package: "FlitsGeohash") ] ) ] ``` -------------------------------- ### Convenience Extension for Geohash Encoding Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt A convenience extension on CLLocationCoordinate2D for a more fluent geohash encoding syntax. Internally calls Geohash.hash(_:length:). ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let coordinate = CLLocationCoordinate2D( latitude: 52.3676, longitude: 4.9041 ) // Using the extension method for cleaner code let amsterdamHash = coordinate.geohash(length: 7) print(amsterdamHash) // "u173zq1" // Chain with other coordinate operations let locations = [ CLLocationCoordinate2D(latitude: 52.3676, longitude: 4.9041), // Amsterdam CLLocationCoordinate2D(latitude: 48.8566, longitude: 2.3522), // Paris CLLocationCoordinate2D(latitude: 51.5074, longitude: -0.1278) // London ] let hashes = locations.map { $0.geohash(length: 5) } print(hashes) // ["u173z", "u09tv", "gcpvj"] ``` -------------------------------- ### Add FlitsGeohash to Package.swift Source: https://github.com/flitsmeister/flitsgeohash/blob/main/README.md Add the FlitsGeohash package to your project's Package.swift file to include it as a dependency. ```swift dependencies: [ .package(url: "https://github.com/flitsmeister/FlitsGeohash.git", from: "1.3.0") ] ``` -------------------------------- ### Typed Region Coverage with Fixed-Length Geohashes Source: https://github.com/flitsmeister/flitsgeohash/blob/main/README.md Generate geohashes covering a region using a fixed-length geohash type, such as Geohash3. This ensures the output geohashes match the specified precision. ```swift let regionHashes = Geohash3.hashesForRegion( centerCoordinate: .init(latitude: 57.64911063015461, longitude: 10.40743969380855), latitudeDelta: 2, longitudeDelta: 2 ) ``` -------------------------------- ### Generate Geohashes for a Region with hashesForRegion() Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Generates typed geohash arrays covering a geographic region. The geohash length is determined by the type, eliminating the need for a length parameter. ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let center = CLLocationCoordinate2D( latitude: 57.64911063015461, longitude: 10.40743969380855 ) // Get Geohash3 cells covering a region let region3: [Geohash3] = Geohash3.hashesForRegion( centerCoordinate: center, latitudeDelta: 2, longitudeDelta: 2 ) print(region3.map(\.string).sorted()) // ["u4n", "u4p", "u4q", "u4r", "u60", "u62"] // Higher precision typed region let region6: [Geohash6] = Geohash6.hashesForRegion( centerCoordinate: CLLocationCoordinate2D(latitude: 52.0, longitude: 5.0), latitudeDelta: 0.02, longitudeDelta: 0.02 ) print("Geohash6 cells in region: \(region6.count)") // Type safety ensures consistent precision func queryDatabase(cells: [Geohash5]) -> [String] { // Database query using 5-character precision return cells.map { "Result for \($0.string)" } } let queryCells: [Geohash5] = Geohash5.hashesForRegion( centerCoordinate: center, latitudeDelta: 0.1, longitudeDelta: 0.1 ) let results = queryDatabase(cells: queryCells) print("Query results: \(results.count)") ``` -------------------------------- ### Generate Geohashes Covering a Region Source: https://github.com/flitsmeister/flitsgeohash/blob/main/README.md Generate a list of geohashes that cover a specified map region defined by a center coordinate and deltas. The length parameter determines the precision of the geohashes. ```swift let hashes = Geohash.hashesForRegion( centerCoordinate: .init(latitude: 57.64911063015461, longitude: 10.40743969380855), latitudeDelta: 2, longitudeDelta: 2, length: 3 ) print(hashes.sorted()) // ["u4n", "u4p", "u4q", "u4r", "u60", "u62"] ``` -------------------------------- ### Use Fixed-Length Geohash Types Source: https://github.com/flitsmeister/flitsgeohash/blob/main/README.md Utilize strongly typed geohashes for specific lengths (1-11) for stricter code. These types provide methods for string conversion, finding neighbors, and converting to lower precision geohashes. ```swift let geohash = Geohash11(coordinate) print(geohash.string) // "u4pruydqqvj" let neighbors = geohash.neighbors() print(neighbors.north.string) // "u4pruydqqvm" let lowerPrecision: Geohash5? = geohash.toLowerLength() print(lowerPrecision?.string as Any) // Optional("u4pru") ``` -------------------------------- ### Encode CLLocationCoordinate2D to Geohash String Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Encodes a CLLocationCoordinate2D into a geohash string with specified precision. Longer lengths offer greater accuracy. Supports lengths from 1 to 22. ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash // Create a coordinate (works on both Apple platforms and Linux) let coordinate = CLLocationCoordinate2D( latitude: 57.64911063015461, longitude: 10.40743969380855 ) // Encode to geohash with different precisions let hash11 = Geohash.hash(coordinate, length: 11) print(hash11) // "u4pruydqqvj" - ~0.6m precision let hash8 = Geohash.hash(coordinate, length: 8) print(hash8) // "u4pruydq" - ~19m precision let hash5 = Geohash.hash(coordinate, length: 5) print(hash5) // "u4pru" - ~2.4km precision let hash3 = Geohash.hash(coordinate, length: 3) print(hash3) // "u4p" - ~156km precision ``` -------------------------------- ### Encode CLLocationCoordinate2D to Geohash Source: https://github.com/flitsmeister/flitsgeohash/blob/main/README.md Encode a CLLocationCoordinate2D to a geohash string with a specified length. On Linux, a compatible coordinate type is provided when CoreLocation is unavailable. ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let coordinate = CLLocationCoordinate2D( latitude: 57.64911063015461, longitude: 10.40743969380855 ) let hash = Geohash.hash(coordinate, length: 11) // "u4pruydqqvj" let shortHash = coordinate.geohash(length: 5) // "u4pru" ``` -------------------------------- ### Typed Geohash API (LengthedGeohash) Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt This section covers the typed geohash API, which provides compile-time type safety for geohash operations. It uses generic types to represent fixed-length geohashes, preventing errors from mixing different precision levels. ```APIDOC ## LengthedGeohash (Typed Geohash) ### Description Provides compile-time type safety for geohash operations using generic types. Type aliases `Geohash1` through `Geohash11` represent fixed-length geohashes, preventing accidental mixing of different precision levels. The typed API mirrors the string-based API but returns typed results. ### Methods #### Initialization - **`Geohash(coordinate: CLLocationCoordinate2D)`**: Creates a typed geohash of length N from a coordinate. - **`Geohash(string: String)`**: Creates a typed geohash of length N from a string. #### Properties - **`string: String`**: Returns the string representation of the typed geohash. #### Neighbor Operations - **`adjacent(direction: NeighborDirection) -> Geohash`**: Returns the adjacent geohash in the specified direction. - **`neighbors() -> Neighbors`**: Returns a struct containing all eight neighbors of the current geohash. - **`Neighbors.north`**, **`Neighbors.south`**, etc. (Geohash): Individual neighbors. - **`Neighbors.allNeighbors`** (Set>): A set of all eight neighbors. - **`Neighbors.allNeighbors(and: Geohash) -> Set>`**: A set of all neighbors including the center geohash. ### Parameters - **N**: A type parameter representing the length of the geohash (e.g., `Geohash5`, `Geohash11`). - **`coordinate`**: A `CLLocationCoordinate2D` for initialization. - **`string`**: A `String` for initialization. - **`direction`**: An enum `NeighborDirection` (e.g., `.north`, `.southEast`). ### Request Example ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let coordinate = CLLocationCoordinate2D(latitude: 57.64911063015461, longitude: 10.40743969380855) // Create typed geohash from coordinate let geohash11 = Geohash11(coordinate) print(geohash11.string) // Create from existing string let geohash5 = Geohash5(string: "u4pru") print(geohash5.string) // Type-safe adjacent operations let northNeighbor: Geohash11 = geohash11.adjacent(direction: .north) print(northNeighbor.string) // Type-safe neighbors let neighbors: Geohash11.Neighbors = geohash11.neighbors() print(neighbors.north.string) print(neighbors.southWest.string) // Get all neighbors as typed Set let allTyped: Set = neighbors.allNeighbors print("Typed neighbor count: \(allTyped.count)") // Include center in the set let gridCells: Set = neighbors.allNeighbors(and: geohash11) print("Grid cells: \(gridCells.count)") ``` ### Response Example (Illustrative - actual output depends on input) ```json { "geohash11_string": "u4pruydqqvj", "geohash5_string": "u4pru", "northNeighbor_string": "u4pruydqqvm", "neighbor_north_string": "u4pruydqqvm", "neighbor_southWest_string": "u4pruydqquu", "allTypedNeighborCount": 8, "gridCellsCount": 9 } ``` ``` -------------------------------- ### Generate Geohashes for a Geographic Region Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Generates all geohashes that cover a rectangular geographic region. Useful for map-based queries to find geohash cells within a visible area. ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash // Cover a region around a coordinate let center = CLLocationCoordinate2D( latitude: 57.64911063015461, longitude: 10.40743969380855 ) // Get geohashes covering a 2° x 2° region at precision 3 let hashes = Geohash.hashesForRegion( centerCoordinate: center, latitudeDelta: 2, longitudeDelta: 2, length: 3 ) print(hashes.sorted()) // ["u4n", "u4p", "u4q", "u4r", "u60", "u62"] // Higher precision for smaller regions (city-level) let cityHashes = Geohash.hashesForRegion( centerCoordinate: CLLocationCoordinate2D(latitude: 52.0, longitude: 5.0), latitudeDelta: 0.5, longitudeDelta: 0.5, length: 6 ) print("City region cells: \(cityHashes.count)") // > 1000 cells // Small region query (neighborhood-level) let localHashes = Geohash.hashesForRegion( centerCoordinate: CLLocationCoordinate2D(latitude: 52.0, longitude: 5.0), latitudeDelta: 0.001, longitudeDelta: 0.001, length: 6 ) print("Local area cells: \(localHashes.count)") // Small number of cells // Edge case: region at equator/prime meridian intersection let equatorHashes = Geohash.hashesForRegion( centerCoordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), latitudeDelta: 0.01, longitudeDelta: 0.01, length: 6 ) print(equatorHashes.sorted()) // ["7zzzzz", "ebpbpb", "kpbpbp", "s00000"] ``` -------------------------------- ### Geohash Neighbors API Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt This section explains how to retrieve the eight neighboring geohashes for a given geohash string. It also shows how to access individual neighbors and collections of neighbors, including the center cell. ```APIDOC ## Geohash.neighbors(hash:) ### Description Returns all eight neighboring geohashes surrounding the given cell. The returned `Neighbors` struct provides direct access to each neighbor by direction and includes helper properties for getting all neighbors as a set. ### Method `Geohash.neighbors(hash: String) -> Neighbors` ### Parameters #### Path Parameters - **hash** (String) - Required - The geohash string for which to find neighbors. ### Response #### Success Response (Neighbors Struct) - **north** (String) - The geohash of the northern neighbor. - **south** (String) - The geohash of the southern neighbor. - **east** (String) - The geohash of the eastern neighbor. - **west** (String) - The geohash of the western neighbor. - **northEast** (String) - The geohash of the northeastern neighbor. - **northWest** (String) - The geohash of the northwestern neighbor. - **southEast** (String) - The geohash of the southeastern neighbor. - **southWest** (String) - The geohash of the southwestern neighbor. - **allNeighbors** (Set) - A set containing all eight neighboring geohashes. - **allNeighbors(and: String) -> Set** - A method that returns a set of all neighbors including the center geohash. ### Request Example ```swift import FlitsGeohash let hash = "u4pruydqqvj" let neighbors = Geohash.neighbors(hash: hash) print(neighbors.north) print(neighbors.allNeighbors.count) print(neighbors.allNeighbors(and: hash).count) ``` ### Response Example ```json { "north": "u4pruydqqvm", "south": "u4pruydqquv", "east": "u4pruydqqvn", "west": "u4pruydqqvh", "northEast": "u4pruydqqvq", "northWest": "u4pruydqqvk", "southEast": "u4pruydqquy", "southWest": "u4pruydqquu", "allNeighbors": ["u4pruydqqvm", "u4pruydqquv", "u4pruydqqvn", "u4pruydqqvh", "u4pruydqqvq", "u4pruydqqvk", "u4pruydqquy", "u4pruydqquu"] } ``` ``` -------------------------------- ### LengthedGeohash.toLowerLength() Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Converts a typed geohash to a lower precision by truncating the string. Returns `nil` if attempting to convert to a higher precision. Converting to the same length returns an equivalent copy. ```APIDOC ## LengthedGeohash.toLowerLength() ### Description Converts a typed geohash to a lower precision by truncating the string. Returns `nil` if attempting to convert to a higher precision (which would require interpolation). Converting to the same length returns an equivalent copy. ### Method Instance method ### Endpoint N/A (Instance method) ### Parameters None ### Request Example ```swift import FlitsGeohash let geohash11 = Geohash11(string: "u4pruydqqvj") let geohash5: Geohash5? = geohash11.toLowerLength() print(geohash5?.string as Any) // Optional("u4pru") let impossible: Geohash11? = Geohash3(string: "u4p").toLowerLength() print(impossible as Any) // nil ``` ### Response #### Success Response (Instance Method Return) - **Geohash Type?** - An optional instance of a lower precision Geohash type, or nil if conversion is not possible (e.g., increasing precision). ``` -------------------------------- ### LengthedGeohash.hashesForRegion Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Static method that generates typed geohash arrays covering a geographic region. The geohash length is determined by the type, eliminating the need for a length parameter. ```APIDOC ## LengthedGeohash.hashesForRegion(centerCoordinate:latitudeDelta:longitudeDelta:) ### Description Static method that generates typed geohash arrays covering a geographic region. The geohash length is determined by the type, eliminating the need for a length parameter. ### Method Static method ### Endpoint N/A (Static method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let center = CLLocationCoordinate2D(latitude: 57.64911063015461, longitude: 10.40743969380855) let region3: [Geohash3] = Geohash3.hashesForRegion(centerCoordinate: center, latitudeDelta: 2, longitudeDelta: 2) print(region3.map(\.string).sorted()) // ["u4n", "u4p", "u4q", "u4r", "u60", "u62"] let region6: [Geohash6] = Geohash6.hashesForRegion(centerCoordinate: CLLocationCoordinate2D(latitude: 52.0, longitude: 5.0), latitudeDelta: 0.02, longitudeDelta: 0.02) print("Geohash6 cells in region: \(region6.count)") ``` ### Response #### Success Response (Static Method Return) - **[Geohash Type]** - An array of geohash strings representing the cells covering the specified region. ``` -------------------------------- ### Geohash Region Coverage API Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt This section details how to generate all geohashes that cover a specified rectangular geographic region. It's useful for map-based queries to find relevant geohash cells within a given area. ```APIDOC ## Geohash.hashesForRegion(centerCoordinate:latitudeDelta:longitudeDelta:length:) ### Description Generates all geohashes that cover a rectangular geographic region defined by a center coordinate and latitude/longitude deltas. This is essential for map-based queries where you need to find all relevant geohash cells within a visible area. ### Method `Geohash.hashesForRegion(centerCoordinate: CLLocationCoordinate2D, latitudeDelta: Double, longitudeDelta: Double, length: Int) -> [String]` ### Parameters #### Path Parameters - **centerCoordinate** (CLLocationCoordinate2D) - Required - The center point of the region. - **latitudeDelta** (Double) - Required - The height of the region in degrees. - **longitudeDelta** (Double) - Required - The width of the region in degrees. - **length** (Int) - Required - The precision (length) of the geohashes to generate. ### Request Example ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let center = CLLocationCoordinate2D(latitude: 57.64911063015461, longitude: 10.40743969380855) let hashes = Geohash.hashesForRegion(centerCoordinate: center, latitudeDelta: 2, longitudeDelta: 2, length: 3) print(hashes.sorted()) ``` ### Response #### Success Response (Array of Strings) - **[String]** - An array of geohash strings that cover the specified region. ### Response Example ```json ["u4n", "u4p", "u4q", "u4r", "u60", "u62"] ``` ``` -------------------------------- ### Convert Geohash Precision with toLowerLength() Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Truncates a geohash string to a lower precision. Returns nil if attempting to increase precision. Converting to the same length returns an equivalent copy. ```swift import FlitsGeohash let geohash11 = Geohash11(string: "u4pruydqqvj") // Convert to lower precision - returns Optional let geohash5: Geohash5? = geohash11.toLowerLength() print(geohash5?.string as Any) // Optional("u4pru") let geohash2: Geohash2? = geohash11.toLowerLength() print(geohash2?.string as Any) // Optional("u4") let geohash10: Geohash10? = geohash11.toLowerLength() print(geohash10?.string as Any) // Optional("u4pruydqqv") // Converting to same length returns equivalent let samePrecision: Geohash11? = geohash11.toLowerLength() print(samePrecision == geohash11) // true // Converting to higher precision returns nil let geohash3 = Geohash3(string: "u4p") let impossible: Geohash11? = geohash3.toLowerLength() print(impossible as Any) // nil ``` -------------------------------- ### Adjacent Geohash Retrieval Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt This section covers how to find the geohash of adjacent cells in cardinal directions. ```APIDOC ## Geohash.adjacent(hash:direction:) ### Description Returns the geohash of the adjacent cell in one of the four cardinal directions (north, south, east, west). This is useful for spatial queries where you need to check neighboring cells for proximity searches or boundary detection. ### Method `Geohash.adjacent(hash:direction:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift import FlitsGeohash let centerHash = "u4pruydqqvj" let north = Geohash.adjacent(hash: centerHash, direction: .north) let south = Geohash.adjacent(hash: centerHash, direction: .south) let east = Geohash.adjacent(hash: centerHash, direction: .east) let west = Geohash.adjacent(hash: centerHash, direction: .west) print("Center: \(centerHash)") print("North: \(north)") // "u4pruydqqvm" print("South: \(south)") // "u4pruydqquv" print("East: \(east)") // "u4pruydqqvn" print("West: \(west)") // "u4pruydqqvh" var current = "u4pru" for _ in 0..<3 { current = Geohash.adjacent(hash: current, direction: .north) print(current) } // Output: "u4prv", "u4pry", "u4prz" ``` ### Response #### Success Response (200) - **adjacent_geohash**: string - The geohash of the adjacent cell. #### Response Example ```json { "adjacent_geohash": "u4pruydqqvm" } ``` ``` -------------------------------- ### Geohash Encoding API Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt This section details how to encode geographic coordinates into geohash strings using the FlitsGeohash library. ```APIDOC ## Geohash.hash(_:length:) ### Description Encodes a `CLLocationCoordinate2D` into a geohash string of the specified length. The length parameter accepts values from 1 to 22, where longer lengths provide greater precision. This is the primary method for converting geographic coordinates to geohash format. ### Method `Geohash.hash(_:length:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let coordinate = CLLocationCoordinate2D( latitude: 57.64911063015461, longitude: 10.40743969380855 ) let hash11 = Geohash.hash(coordinate, length: 11) print(hash11) // "u4pruydqqvj" let hash8 = Geohash.hash(coordinate, length: 8) print(hash8) // "u4pruydq" let hash5 = Geohash.hash(coordinate, length: 5) print(hash5) // "u4pru" let hash3 = Geohash.hash(coordinate, length: 3) print(hash3) // "u4p" ``` ### Response #### Success Response (200) - **geohash**: string - The geohash string representation of the coordinates. #### Response Example ```json { "geohash": "u4pruydqqvj" } ``` ## CLLocationCoordinate2D.geohash(length:) ### Description A convenience extension on `CLLocationCoordinate2D` that provides a more fluent syntax for encoding coordinates to geohash strings. This method internally calls `Geohash.hash(_:length:)` and produces identical results. ### Method `coordinate.geohash(length:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let coordinate = CLLocationCoordinate2D( latitude: 52.3676, longitude: 4.9041 ) let amsterdamHash = coordinate.geohash(length: 7) print(amsterdamHash) // "u173zq1" let locations = [ CLLocationCoordinate2D(latitude: 52.3676, longitude: 4.9041), // Amsterdam CLLocationCoordinate2D(latitude: 48.8566, longitude: 2.3522), // Paris CLLocationCoordinate2D(latitude: 51.5074, longitude: -0.1278) // London ] let hashes = locations.map { $0.geohash(length: 5) } print(hashes) // ["u173z", "u09tv", "gcpvj"] ``` ### Response #### Success Response (200) - **geohash**: string - The geohash string representation of the coordinates. #### Response Example ```json { "geohash": "u173zq1" } ``` ``` -------------------------------- ### Typed Geohash Operations with LengthedGeohash Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Provides compile-time type safety for geohash operations using generic types. Type aliases like Geohash1 through Geohash11 prevent mixing different precision levels. ```swift #if canImport(CoreLocation) import CoreLocation #endif import FlitsGeohash let coordinate = CLLocationCoordinate2D( latitude: 57.64911063015461, longitude: 10.40743969380855 ) // Create typed geohash from coordinate let geohash11 = Geohash11(coordinate) print(geohash11.string) // "u4pruydqqvj" // Create from existing string let geohash5 = Geohash5(string: "u4pru") print(geohash5.string) // "u4pru" // Type-safe adjacent operations let northNeighbor: Geohash11 = geohash11.adjacent(direction: .north) print(northNeighbor.string) // "u4pruydqqvm" // Type-safe neighbors let neighbors: Geohash11.Neighbors = geohash11.neighbors() print(neighbors.north.string) // "u4pruydqqvm" print(neighbors.southWest.string) // "u4pruydqquu" // Get all neighbors as typed Set let allTyped: Set = neighbors.allNeighbors print("Typed neighbor count: \(allTyped.count)") // 8 // Include center in the set let gridCells: Set = neighbors.allNeighbors(and: geohash11) print("Grid cells: \(gridCells.count)") // 9 ``` -------------------------------- ### Geohash.Neighbors Struct Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt A struct containing all eight neighboring geohashes with named properties for each direction. Provides convenience methods for working with neighbor sets. ```APIDOC ## Geohash.Neighbors Struct ### Description A struct containing all eight neighboring geohashes with named properties for each direction. Provides convenience methods for working with neighbor sets. ### Method Instance method (accessed via `Geohash.neighbors(hash:)`) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift import FlitsGeohash let hash = "gcpvj" let neighbors: Geohash.Neighbors = Geohash.neighbors(hash: hash) let neighborSet: Set = neighbors.allNeighbors print("Unique neighbors: \(neighborSet.count)") // 8 let fullGrid: Set = neighbors.allNeighbors(and: hash) print("Full grid cells: \(fullGrid.count)") // 9 func areAdjacent(_ hash1: String, _ hash2: String) -> Bool { return Geohash.neighbors(hash: hash1).allNeighbors.contains(hash2) } print(areAdjacent("gcpvj", neighbors.north)) // true ``` ### Response #### Success Response (Struct Properties) - **north** (String) - The geohash of the northern neighbor. - **northEast** (String) - The geohash of the northeastern neighbor. - **east** (String) - The geohash of the eastern neighbor. - **southEast** (String) - The geohash of the southeastern neighbor. - **south** (String) - The geohash of the southern neighbor. - **southWest** (String) - The geohash of the southwestern neighbor. - **west** (String) - The geohash of the western neighbor. - **northWest** (String) - The geohash of the northwestern neighbor. #### Methods - **allNeighbors** (Set) - Returns a set of all 8 neighboring geohashes. - **allNeighbors(and: String)** (Set) - Returns a set including the center geohash and all 8 neighbors. ``` -------------------------------- ### Find Adjacent Geohashes with Geohash.Direction Enum Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Defines the four cardinal directions for adjacent cell lookups. The enum is Sendable for safe use in concurrent code. Use in pathfinding or grid traversal. ```swift import FlitsGeohash // Available directions let directions: [Geohash.Direction] = [.north, .east, .south, .west] let startHash = "u4pru" // Iterate through all directions for direction in directions { let adjacent = Geohash.adjacent(hash: startHash, direction: direction) print("\(direction): \(adjacent)") } // Output: // north: u4prv // east: u4prg // south: u4prj // west: u4prt // Use in pathfinding or grid traversal func walk(from start: String, path: [Geohash.Direction]) -> String { var current = start for direction in path { current = Geohash.adjacent(hash: current, direction: direction) } return current } let destination = walk(from: "u4pru", path: [.north, .north, .east]) print(destination) // Moved 2 cells north, 1 cell east ``` -------------------------------- ### Find Adjacent Geohash Cells Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Returns the geohash of the adjacent cell in one of the four cardinal directions (north, south, east, west). Useful for spatial queries and proximity searches. ```swift import FlitsGeohash let centerHash = "u4pruydqqvj" // Get adjacent cells in each direction let north = Geohash.adjacent(hash: centerHash, direction: .north) let south = Geohash.adjacent(hash: centerHash, direction: .south) let east = Geohash.adjacent(hash: centerHash, direction: .east) let west = Geohash.adjacent(hash: centerHash, direction: .west) print("Center: \(centerHash)") print("North: \(north)") // "u4pruydqqvm" print("South: \(south)") // "u4pruydqquv" print("East: \(east)") // "u4pruydqqvn" print("West: \(west)") // "u4pruydqqvh" // Walking in a direction multiple times var current = "u4pru" for _ in 0..<3 { current = Geohash.adjacent(hash: current, direction: .north) print(current) } // Output: "u4prv", "u4pry", "u4prz" ``` -------------------------------- ### Geohash.Direction Enum Source: https://context7.com/flitsmeister/flitsgeohash/llms.txt Defines the four cardinal directions used for adjacent cell lookups. The enum is `Sendable` for safe use in concurrent code. ```APIDOC ## Geohash.Direction Enum ### Description Defines the four cardinal directions used for adjacent cell lookups. The enum is `Sendable` for safe use in concurrent code. ### Method N/A (Enum definition) ### Endpoint N/A ### Parameters None ### Request Example ```swift import FlitsGeohash let directions: [Geohash.Direction] = [.north, .east, .south, .west] let startHash = "u4pru" for direction in directions { let adjacent = Geohash.adjacent(hash: startHash, direction: direction) print("\(direction): \(adjacent)") } // Output: north: u4prv east: u4prg south: u4prj west: u4prt ``` ### Response #### Success Response (Enum Cases) - **north** - Represents the northern direction. - **east** - Represents the eastern direction. - **south** - Represents the southern direction. - **west** - Represents the western direction. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.