Issue with drawing polylines on iOS11 beta 4? - mkmapview

I'm having trouble drawing polylines, and I think I've deduced it to being an issue with iOS 11 beta 4. It was working yesterday with the same code, and now I've updated to beta 4 and it doesn't draw polylines.
Just confirmed this by trying it in Xcode 8 on iOS 10.3 simulator, and in Xcode 9b4 on the iOS 11b4 simulator.
Code:
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
let mapView = MKMapView()
override func viewDidLoad() {
super.viewDidLoad()
mapView.frame = CGRect(x: 10, y: 10, width: 300, height: 300)
mapView.delegate = self
mapView.region = MKCoordinateRegionMake(CLLocationCoordinate2D(latitude: 51.482736, longitude: -0.015253), MKCoordinateSpanMake(0.005, 0.005))
mapView.delegate = self
let coordinate1 = CLLocationCoordinate2D(latitude: 51.482736, longitude: -0.015253)
let coordinate2 = CLLocationCoordinate2D(latitude: 51.482736, longitude: -0.016253)
let polyline = MKPolyline(coordinates: [coordinate1, coordinate2], count: 2)
mapView.add(polyline, level: .aboveLabels)
view.addSubview(mapView)
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let renderer = MKPolylineRenderer(overlay: overlay)
renderer.strokeColor = UIColor.red
renderer.lineWidth = 4.0
return renderer
}
}
iOS 10:
iOS 11:
Annotations are added to the map without issue.

Fixed in beta 5. We just had to wait.

Related

Adding UIView on top of react native navigation

I am using react-native-navigation and trying to add a native view on the top of everything. I initialized the Swift class in AppDelegate and call swift func:
func showUp() {
let window = UIApplication.shared.keyWindow!
let rect = UIView(frame: CGRect(x: 50, y: 50, width: 100, height: 50))
rect.backgroundColor = UIColor.white
window.addSubview(rect) }
The View seemed to be appeared while loading app and then disappears after app is
loaded.
Thanks in advance)

Setting permanent Map Camera Angle in Hybrid Flyover

The app I am developing(using Xcode 9 and swift 4) requires the user to move through the map in hybrid flyover mode. I have achieved that much, but I want to permanently change the angle (so they can see buildings and statues) as the navigate through the map. As of right now they can see the map from directly overhead and have the adjust angles manually. below is the code I have used so far
let distance: CLLocationDistance = 650
let pitch: CGFloat = 65
let heading = 0.0
var camera: MKMapCamera?
override func viewDidLoad() {
super.viewDidLoad()
mapView.mapType = .satelliteFlyover
let coordinate = CLLocationCoordinate2D(latitude: 40.7484405,
`enter code here` longitude: -73.9856644)
camera = MKMapCamera(lookingAtCenter: coordinate,
fromDistance: distance,
pitch: pitch,
heading: `enter code here`heading)
mapView.camera = camera!
}
#IBAction func animateCamera(_ sender: AnyObject) {
}

xCode 9: UITextView not initialized

Once I switched to xCode 9, my initialization of a UITextView stopped working:
#IBOutlet weak var txtPirepText: UITextView!
override func viewDidLoad()
{
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad
{
self.txtPirepText = UITextView(frame: CGRect(x: 60, y: 380, width: 900, height: 280))
print("IS THIS VALUE NIL? ",self.txtPirepText)
self.txtPirepText.text = ""
self.txtPirepText.font = UIFont(name: "Arial-BoldMT", size: 17)
self.txtPirepText.textColor = UIColor.black
}
}
The print shows that the value is nil and the application crashes on trying to set a text.
Does such initialization not work any more? Thank you!

open override var description: String not called in Swift 3

I'm now using Xcode 8 GM (Version 8.0 (8A218a)) with Swift 3, my repo is: https://github.com/yeahdongcn/UIColor-Hex-Swift/tree/Swift-3.0 after I converted the Swift 2 syntax to Swift 3, I set two breakpoints in the following getter then I ran the test, the first one is not called, but the 2nd debugDescription gets called.
open override var description: String {
return self.hexString(true)
}
open override var debugDescription: String {
return self.hexString(true)
}
I created a playground it works the same
//: Playground - noun: a place where people can play
import UIKit
extension UIColor {
public func hexString(_ includeAlpha: Bool) -> String {
var r: CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
self.getRed(&r, green: &g, blue: &b, alpha: &a)
if (includeAlpha) {
return String(format: "#%02X%02X%02X%02X", Int(r * 255), Int(g * 255), Int(b * 255), Int(a * 255))
} else {
return String(format: "#%02X%02X%02X", Int(r * 255), Int(g * 255), Int(b * 255))
}
}
open override var description: String {
return self.hexString(true)
}
open override var debugDescription: String {
return self.hexString(true)
}
}
let color = UIColor.yellow
color.description
color.debugDescription
You cannot override a method in an extension. You would need to use a subclass. The compiler should be complaining.
It might have worked in Swift 2.x, but that was not correct behavior.

iphone:How to use index number on map pin in MKAnnotation View?

Hello friends,
I am developing a functionality to display index number on map pin and set image on mapview of iPhone so please tell me any link or any idea to develop this functionality.
Thanks in advance.
What is an index number in the context? Is it just a digit that your code is displaying? If so your question is how to display text on a map. Use a map overlay. Same for images. Search for MKMapOverlay and go from there.
I have use this method for index number in annotation view.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
return nil
}
// Better to make this class property
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = MKAnnotationView()
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView.frame = CGRect(x: annotationView.frame.origin.x, y: annotationView.frame.origin.y, width: 80, height: 200)
annotationView.annotation = annotation
annotationView.tag = index
index += 1
let imageViewPin = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 40))
imageViewPin.center = CGPoint(x: annotationView.center.x, y: annotationView.center.y - 11)
imageViewPin.image = UIImage(named: "green_pin")
annotationView.addSubview(imageViewPin)
return annotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
debugPrint(view.tag)
}

Resources