And here is a snippet of the GeoJSON structure
I am trying to build an app that shows some areas(polygons/overlays) on the map and when a polygon is tapped I would like to print on console print("Polygon \(zone_id) has been tapped"). The polygons are rendered from a GeoJSON file where we can also find the zone_id in the properties feature. So far I rendered the overlays on the map but I am stuck and I appreciate some guidance where to go from here.
I will paste my code that I have so far and also a snippet of the GeoJSON file.
import SwiftUI
import CoreLocation
struct Home: View {
@StateObject var mapData = MapViewModel()
var body: some View {
ZStack{
MapView()
.environmentObject(mapData)
.ignoresSafeArea(.all, edges: .all)
}
}
}
struct Home_Previews: PreviewProvider {
static var previews: some View {
Home()
}
}
import SwiftUI
import MapKit
struct MapView: UIViewRepresentable {
@EnvironmentObject var mapData: MapViewModel
@State var restrictions: [MKOverlay] = []
func makeCoordinator() -> Coordinator {
return MapView.Coordinator()
}
func makeUIView(context: Context) -> MKMapView {
let view = mapData.mapView
view.showsUserLocation = true
view.delegate = context.coordinator
mapData.showRestrictedZones { (restrictions) in
self.restrictions = restrictions
view.addOverlays(self.restrictions)
}
return view
}
func updateUIView(_ uiView: MKMapView, context: Context) {
}
class Coordinator: NSObject, MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if let polygon = overlay as? MKPolygon {
let renderer = MKPolygonRenderer(polygon: polygon)
renderer.fillColor = UIColor.purple.withAlphaComponent(0.2)
renderer.strokeColor = .purple.withAlphaComponent(0.7)
return renderer
}
return MKOverlayRenderer(overlay: overlay)
}
}
}
import SwiftUI
import MapKit
// All Map Data Goes here...
class MapViewModel: NSObject, ObservableObject {
@Published var mapView = MKMapView()
// Decode GeoJSON from the server
func showRestrictedZones(completion: @escaping ([MKOverlay]) -> ()) {
guard let url = URL(string: "https://flightplan.romatsa.ro/init/static/zone_restrictionate_uav.json") else {
fatalError("Unable to get geoJSON") }
downloadData(fromURL: url) { (returnedData) in
if let data = returnedData {
var geoJson = [MKGeoJSONObject]()
do {
geoJson = try MKGeoJSONDecoder().decode(data)
} catch {
fatalError("Unable to decode GeoJSON")
}
var overlays = [MKOverlay]()
for item in geoJson {
if let feature = item as? MKGeoJSONFeature {
for geo in feature.geometry {
if let polygon = geo as? MKPolygon {
overlays.append(polygon)
}
}
}
}
DispatchQueue.main.async {
completion(overlays)
}
}
}
}
func downloadData( fromURL url: URL, completion: @escaping (_ data: Data?) -> ()) {
URLSession.shared.dataTask(with: url) { (data, response, error) in
guard
let data = data,
error == nil,
let response = response as? HTTPURLResponse,
response.statusCode >= 200 && response.statusCode < 300 else {
print("Error downloading data.")
completion(nil)
return
}
completion(data)
}
.resume()
}
}
Post
Replies
Boosts
Views
Activity
I am trying to detect wether two MKOverlays (might be circles or polygons) intersect.
Tried using boundingMapRect but it draws a rectangle around my overlay thus giving me inaccurate results.
if polygon != nil {
intersectionOverlay = polygon!
} else {
intersectionOverlay = circle!
}
for overlay: MKOverlay in mapView.overlays {
let rect = overlay.boundingMapRect
if rect.intersects(intersectionOverlay.boundingMapRect) {
print("Intersects \(overlay.title)")
}
Using that piece of code, would return true for the situation in the images below. Is there any other better way to achieve the desired results? Thanks
Hello,
My app has been approved on March 14, 2023 and has the status "Ready for sale" ever since. But the app is still not available on App Store, and whenever i use the link in App Connect to view on App Store it says "App Not available. This app is currently not available in your country or region". Initially I made the app only available in my country, after few days of getting that error, I made it available worldwide but still can't seem to find my app being available. I've sent a support ticket to apple a few days ago but got no reply.
In the approval email it said it may take up to 24 hours for the app to be available on App Store, but few days have passed and still not available on app store.
The app is free, and i checked all the countries and regions for availability. What can be the problem, how long does it take?
Thank you