Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions MapboxSceneKit/TerrainNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ open class TerrainNode: SCNNode {
self.init(southWestCorner: CLLocation(latitude: minLat, longitude: minLon),
northEastCorner: CLLocation(latitude: maxLat, longitude: maxLon))
}

@objc public convenience init(lat: CLLocationDegrees, lon: CLLocationDegrees, distanceInKm: Double ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to maybe have the center coordinate as a CLLocation rather than having it as latitude and longitude?


// https://coderwall.com/p/otkscg/geographic-searches-within-a-certain-distances
// Generates approximately accurate bounding box around a center latitude longitude point.
let earthRadius: Double = 6371

let maxLat: Double = lat + Math.radiansToDegrees(distanceInKm / earthRadius)
let minLat: Double = lat - Math.radiansToDegrees(distanceInKm / earthRadius)

let maxLon: Double = lon + Math.radiansToDegrees(distanceInKm / earthRadius / cos(Math.degreesToRadians(lat)))
let minLon: Double = lon - Math.radiansToDegrees(distanceInKm / earthRadius / cos(Math.degreesToRadians(lat)))

self.init(southWestCorner: CLLocation(latitude: minLat, longitude: minLon),
northEastCorner: CLLocation(latitude: maxLat, longitude: maxLon))
}

deinit {
for task in pendingFetches {
Expand Down