Post

Replies

Boosts

Views

Activity

Reply to Apple Maps vs MapKit Satellite Image Quality
It seems the maptypes are now named like this, according to https://developer.apple.com/documentation/mapkit/mkmaptype : case standard A street map that shows the position of all roads and some road names. case satellite Satellite imagery of the area. case hybrid A satellite image of the area with road and road name information layered on top. case satelliteFlyover A satellite image of the area with flyover data where available. case hybridFlyover A hybrid satellite image with flyover data where available. case mutedStandard A street map where your data is emphasized over the underlying map details.
May ’21
Reply to MKMapView: Why are my MKPolyline(s) invisible?
Thank you very much to both of you! Now it works! I choose the solution where the code is put in the KMLparser and not in the main file. That seems more correct and as kind of a preparation for implementing detecting style elements inside Linestring. But since I don't have different styles on different lines, I haven't bothered enhancing the parser itself. I am still a beginner in Swift. :-)
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to MKPolyline 'inside' an MKOverlay: How do I access the points that construct the line?
Thank you very much to both of you! Now it works! I choose the solution where the code is put in the KMLparser and not in the main file. That seems more correct and as kind of a preparation for implementing detecting style elements inside Linestring. But since I don't have different styles on different lines, I haven't bothered enhancing the parser itself. I am still a beginner in Swift. :-)
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to MKPolyline 'inside' an MKOverlay: How do I access the points that construct the line?
Thank you very much! When converted like that, the geographic coordinates look perfect. So the overall question still remains: Why are none of the MKPolyline(s) visible on the map? For more information on this project, see https://developer.apple.com/forums/thread/680107 This is the main swift file in the KMLviewer project: swift // // KMLViewerViewController.swift // KMLViewer // // Translated by OOPer in cooperation with shlab.jp, on 2015/10/17. // // /* Copyright (C) 2015 Apple Inc. All Rights Reserved. See LICENSE.txt for this sample’s licensing information Abstract: Displays an MKMapView and demonstrates how to use the included KMLParser class to place annotations and overlays from a parsed KML file on top of the MKMapView./ import UIKit import MapKit @objc(KMLViewerViewController) class KMLViewerViewController: UIViewController, MKMapViewDelegate { @IBOutlet private weak var map: MKMapView! private var kmlParser: KMLParser! override func viewDidLoad() { super.viewDidLoad() map.mapType = .hybridFlyover // Locate the path to the file in the application's bundle // and parse it with the KMLParser. let url = Bundle.main.url(forResource: "KML_Sample", withExtension: "kml")! self.kmlParser = KMLParser(url: url) self.kmlParser.parseKML() // Add all of the MKOverlay objects parsed from the KML file to the map. let overlays = self.kmlParser.overlays overlays.forEach {overlay in if let polyline = overlay as? MKPolyline { var coords = Array(repeating: CLLocationCoordinate2D(), count: polyline.pointCount) polyline.getCoordinates(&coords, range: NSRange(0..polyline.pointCount)) print(coords) } } self.map.addOverlays(overlays) let temp_debug = overlays.map {$0 as! MKPolyline}.map {Array(UnsafeBufferPointer(start:$0.points(),count:$0.pointCount))} // Add all of the MKAnnotation objects parsed from the KML file to the map. let annotations = self.kmlParser.points self.map.addAnnotations(annotations) // Walk the list of overlays and annotations and create a MKMapRect that // bounds all of them and store it into flyTo. var flyTo = MKMapRect.null for overlay in overlays { if flyTo.isNull { flyTo = overlay.boundingMapRect } else { flyTo = flyTo.union(overlay.boundingMapRect) } } for annotation in annotations { let annotationPoint = MKMapPoint(annotation.coordinate) let pointRect = MKMapRect(x: annotationPoint.x, y: annotationPoint.y, width: 0, height: 0) if flyTo.isNull { flyTo = pointRect } else { flyTo = flyTo.union(pointRect) } } // Position the map so that all overlays and annotations are visible on screen. self.map.visibleMapRect = flyTo } //MARK: MKMapViewDelegate func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) - MKOverlayRenderer { return self.kmlParser.rendererForOverlay(overlay)! } func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) - MKAnnotationView? { return self.kmlParser.viewForAnnotation(annotation) } }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to MKPolyline 'inside' an MKOverlay: How do I access the points that construct the line?
Thank you! That command is a bit cryptic to me... :-) And the result is not exactly as expected - I mean latitudes and longitudes are within [-90;+90] and [-180;+180], but the numbers below are much much larger? (lldb) po overlays.map {$0 as! MKPolyline}.map {Array(UnsafeBufferPointer(start:$0.points(),count:$0.pointCount))} ▿ 10 elements ▿ 0 : 2 elements ▿ 0 : MKMapPoint x : 117883367.59539957 y : 70861444.881933 ▿ 1 : MKMapPoint x : 118607415.83505598 y : 70680834.53921854 ▿ 1 : 2 elements ▿ 0 : MKMapPoint x : 118441733.74494734 y : 71578008.7574973 ▿ 1 : MKMapPoint x : 117749165.70252322 y : 71814479.09122863 ▿ 2 : 2 elements ▿ 0 : MKMapPoint x : 118311383.29024056 y : 71083267.28620416 ▿ 1 : MKMapPoint x : 119039612.1903483 y : 70938560.8337035 ▿ 3 : 2 elements ▿ 0 : MKMapPoint x : 117349946.79156 y : 71842649.73875001 ▿ 1 : MKMapPoint x : 117798366.05769886 y : 72412616.11056598 ▿ 4 : 2 elements ▿ 0 : MKMapPoint x : 117630562.56314905 y : 70896032.54940976 ▿ 1 : MKMapPoint x : 116901460.90088205 y : 71039800.62831044 ▿ 5 : 2 elements ▿ 0 : MKMapPoint x : 117238216.79458134 y : 71348308.82833827 ▿ 1 : MKMapPoint x : 117001456.46769533 y : 72040794.67949402 ▿ 6 : 2 elements ▿ 0 : MKMapPoint x : 117987254.6410381 y : 72066796.5154083 ▿ 1 : MKMapPoint x : 118291226.77453867 y : 71401739.6663419 ▿ 7 : 2 elements ▿ 0 : MKMapPoint x : 117274415.68432339 y : 71712389.33240001 ▿ 1 : MKMapPoint x : 116717162.22724375 y : 71232706.02820335 ▿ 8 : 2 elements ▿ 0 : MKMapPoint x : 118103113.58567446 y : 70920013.76664141 ▿ 1 : MKMapPoint x : 117442255.64753546 y : 71255771.67482962 ▿ 9 : 2 elements ▿ 0 : MKMapPoint x : 118404987.20831521 y : 71705176.99185553 ▿ 1 : MKMapPoint x : 119010223.05936122 y : 72110774.61697051 (lldb)
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to KMLViewer (Map Kit): MKPointAnnotation text not displayed
Thank you very much!! I can see now that MKMarkerAnnotationView has variables/properties to turn the displaying of a title and a subtitle on/off, but MKPinAnnotationView does not have such logic. (Strange.) But... :-) There is still a problem: Unless you zoom in, one or more MKPointAnnotation(s) are not shown at all, and on other MKPointAnnotation(s) the title text is missing. For my purpose, I want all information to be displayed all the time. This subject - how many annotations to draw on the map - is described here: https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html Excerpts: " All annotations are drawn at the same scale every time, regardless of the map’s current zoom level. If your map contains many annotations, your annotation views could overlap each other as the user zooms out. To counter this behavior, you can add and remove annotations based on the map’s current zoom level. ... Implementing the logic necessary to add and remove annotations is your responsibility. ... The only way to eliminate annotation overcrowding is to remove some of the annotation objects from the map view. This typically involves implementing the mapView:regionWillChangeAnimated: and mapView:regionDidChangeAnimated: methods to detect changes in the map zoom level. During a zoom change, you can add or remove annotations as needed based on their proximity to one another. You might also consider other criteria (such as the user’s current location) to eliminate some annotations. " According to that, it is the KMLviewer code that removes annotations based on zoom level. But where is that code? I can't find any 'regionWillChangeAnimated' or 'regionDidChangeAnimated' in the code. Thank you!
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to KMLViewer (Map Kit): MKPointAnnotation text not displayed
Yes, that works perfectly! Thank you! When I searched for information on displaying maps on iOS I found this: https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/LocationAwarenessPG/MapKit/MapKit.html And the part about MKmapview NOT showing all annotations here: https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW45 Now that you mention it, I can see that it might be outdated archived documentation. But that was what I found when I searched, and it doesn't refer you to any newer versions, so I assumed it was up-to-date. But again: Thank you very much! Now it looks perfect.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21