Skip to content
Draft
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion Mage/Geocoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//

import Foundation

import MapKit
import CoreLocation
import GARS
import MGRS

Expand All @@ -26,6 +27,7 @@ class GeocoderResult {
var name: String
var address: String? = nil
var location: CLLocationCoordinate2D? = nil
var region: MKCoordinateRegion? = nil

init(name: String, address: String? = nil, location: CLLocationCoordinate2D? = nil) {
self.name = name
Expand Down
23 changes: 22 additions & 1 deletion Mage/NativeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import MapKit
import CoreLocation

class NativeService {
func search(text: String, region: MKCoordinateRegion? = nil, completion: @escaping ((SearchResponse) -> Void)) {
Expand Down Expand Up @@ -35,7 +36,27 @@ class NativeService {
placemark.countryCode
].compactMap { $0 }.joined(separator: ", ")

return GeocoderResult(name: placemark.name ?? text, address: address, location: placemark.location?.coordinate)
// FIXME: Experimental code to explore changing the region displayed so that Fiji can fill the entire map, rather than the ocean at "street view" (wrong zoom level for a country)
// return GeocoderResult(name: placemark.name ?? text, address: address, location: placemark.location?.coordinate)
var result = GeocoderResult(name: placemark.name ?? text, address: address, location: placemark.location?.coordinate)
// result.region = placemark.region



// var itemRegion: MKCoordinateRegion? = nil

if let circularRegion = placemark.region as? CLCircularRegion { // FIXME: CLCircularRegion deprecated use CLCircularGeographicCondition on iOS 17+ (dependent on upping the min version for next release)
// Convert the circle's radius (meters) to a Map Span (degrees)
// Rule of thumb: 1 degree of latitude is ~111,000 meters
let diameter = circularRegion.radius * 2.0
let degrees = diameter / 111000.0

// Add a little padding (1.2x)
let span = MKCoordinateSpan(latitudeDelta: degrees * 1.5, longitudeDelta: degrees * 1.5)
result.region = MKCoordinateRegion(center: placemark.coordinate, span: span)
}

return result
}

completion(SearchResponse.success(type: .geocoder, results: results))
Expand Down
7 changes: 7 additions & 0 deletions Mage/NominatimService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class NominatimService {
let location = geometry?.degreesCentroid().map { centroid in
CLLocationCoordinate2D(latitude: centroid.y.doubleValue, longitude: centroid.x.doubleValue)
}

if let bbox = feature["bbox"] as? [Double] {
// FIXME: Nominatim/GeoJSON usually provides bbox as [minLon, minLat, maxLon, maxLat], we'd need to use similar logic to Native service for properly containing point of interest at it's natural zoom level via the bbox
// Store it in properties so your UI can find it later
// properties["bbox"] = bbox
print(bbox)
}

return GeocoderResult(name: name, address: address, location: location)
}) ?? []
Expand Down