Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Restaurant Reviews App Adding Reviews and a Map Creating Restaurant Pins

McIvor Steiner
McIvor Steiner
9,971 Points

How to just pass the businesses to the 'addAnnotations' method?

In this video, you ran into an issue where it was not working if you just passed the businesses to the addAnnotations method on the map. The business object does conform to the MKAnnotation protocol, so this should work, and would be a lot simpler than the solution that was used in the video. Has anyone determined how to make the first approach work?

Angus Muller
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Angus Muller
iOS Development Techdegree Graduate 12,473 Points

For me it worked straight away with the first way of doing it (addAnnotation method) without having to implerment the second way that was shown , I don't know why it worked for me though?

2 Answers

Sarah Hurtgen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Hurtgen
Treehouse Project Reviewer

In the video he accidentally typed longitude instead of latitude in the YelpBusiness extension, if you follow exactly what he typed, it won't work - but if you follow what he says, it should work fine!

// his original line
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: location.longitude, longitude: location.longitude)
    }
// how it should read
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
    }
Nathan F.
Nathan F.
30,773 Points

I wondered what his error was because it worked perfectly fine for me. That makes sense! Haha

Don't make the same mistake as I did when adding the annotations.

Apple as 2 methods defined. One has an "s" (annotations) accept an array of MKAnnotations And the other is not an arrays

open func addAnnotation(_ annotation: MKAnnotation)

open func addAnnotations(_ annotations: [MKAnnotation])