tvOS beta 9.2 mapkit pins do not show - should they?

I'm using the following code:


        MKPointAnnotation *poi = [[MKPointAnnotation alloc] init];
        poi.coordinate = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);       
        [self.mapCameraPins addObject:poi];
        [self.mapView addAnnotations:self.mapCameraPins];


This should add a pin on the map. It does not.

My other code to zoom into the region etc all works fine.


How do I determine if it's my bug? Or a beta bug?


- David

Replies

I have markers showing on mine so it's not a bug in mapkit. What I found to be an issue at first was that I am fetching my markers from a web service, so to get the markers to show I have to send them to the main queue for display. In Swift:


  let customMarker = CustomMarker(title: "\(record.objectAtIndex(0))",
       locationName: "\(record.objectAtIndex(1))",
       coordinate: CLLocationCoordinate2D(latitude: Double(record.objectAtIndex(3) as! NSNumber), longitude: Double(record.objectAtIndex(4) as! NSNumber)))
  dispatch_async(dispatch_get_main_queue(), { () -> Void in
       self.mapView.addAnnotation(customMarker)
  })

Thank you for your reply. I really appreciate it.


I still cannot get mine to work.

Also interesting is that the delegate call back never gets called.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation


And when I click on it for help - xcode just says it is declared in my .m file. It's very strange.



What capabilities have you enabled for your project?

Have you added any entries to your info.plist for the project?


- David

Wait...


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation


is being called now... what did I do?

... hmmm shifted #import <MapKit/MapKit.h>

from the .m file to the .h file


Clean and compile...

Quick Help still isn't doing anything. I may exit xcode and restart for that.



[EDIT] And now it's not being called.... this is weird...

I'd quit and restarted XCODE and the Simulator with it...


- David

I love it when that happens!


I guess the thing we have to remember while playing with MapKit here is that we are dealing with betas. I'm getting some nice results very quickly but I'm also finding some things a bit quirky at first.

This swift code is working for me.


import MapKit
class ViewController: UIViewController, MKMapViewDelegate {


  @IBAction func searchButtonPushed(sender: AnyObject) {

  let request = MKLocalSearchRequest()
  request.naturalLanguageQuery = searchText.text
  request.region = mapView.region
  let search = MKLocalSearch(request: request)
  search.startWithCompletionHandler({ (response, error) -> Void in
       self.mapItems.removeAllObjects()
       self.mapView.removeAnnotations(self.mapView.annotations)

       for item:MKMapItem in response!.mapItems {
            let point = MKPointAnnotation()

            point.coordinate = item.placemark.coordinate
            point.title = item.placemark.name
            point.subtitle = item.phoneNumber

            self.mapView.addAnnotation(point)
            self.mapItems.addObject(item)
       }

       self.mapView.showAnnotations(self.mapView.annotations, animated: true)
       self.mapItemFrom = nil
       self.mapItemTo = nil

       self.tableView.reloadData()
       })
  }


Hope this help you.


Yos

I have managed to resolve the issues I was having.


Two points to note:


        MKPointAnnotation *poi = [[MKPointAnnotation alloc] init];
        poi.coordinate = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
        poi.title = camera.title;
        poi.subtitle = camera.url;
     
        [self.mapCameraPins addObject:poi];
        [self.mapView addAnnotations:self.mapCameraPins];


My array self.mapCameraPins had not been initialised. ALLOC/INIT - so that was a stupid thing... and I feel dumb.


- (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
.
.
.
        annotationView.canShowCallout = YES;
        annotationView.image = [UIImage imageNamed:@"07-map-marker"];


I needed to set an image to be displayed.


Thank you everyone for your help and guidance.


I'm now on Beta 3 - although that's probably irrelivant.


- David