Paparazzi3 map annotations

9 views
Skip to first unread message

redbirdo

unread,
Mar 9, 2010, 6:05:43 PM3/9/10
to iPhone Application Development Auditors
I've implemented the basic functionality of Paparazzi3 and was
mightily relieved to find it a walk in the park compared to
Paparazzi2! (which will hopefully be good news to those of you still
grappling with it...)

Of course the extra credit part may be another story... should I
bother?!

Anyway, I struggled a bit with the last bit - adding annotations to
the map view which contain the photo title, user name and a disclosure
button which displays the photo.

According to the assignment walkthrough: "you can get all of the
expected functionality using just the following:
- MKMapView - MKMapViewDelegate - MKPlacemark"

I've got it working but I presume I haven't done it the 'right' way as
I couldn't get it to work with MKPlacemark! In the end I created my
own implementation of the MKAnnotation protocol, which is initialized
with a Photo and retrieves the required details from it. Any advice on
how to display the photo title and username using MKPlacemark would be
appreciated. I figure I could have sub-classed it but that seemed a)
naff and b) as much work as implementing my own MKPhotoAnnotation
which has the photo in it ready to display when the disclosure button
is pressed.

I also found it really tricky to get the disclosure button displayed.
I'm not sure if I was missing something obvious?

Vicki

tda95lex

unread,
Mar 10, 2010, 4:29:24 AM3/10/10
to iPhone Application Development Auditors
How did you do it?
I have implemented the MKAnntation protocol, i have put pins on the
map, but i don't know haw so show title and implement touch to push
another view on stack.
Is there any good tutorial for custom annotation?

redbirdo

unread,
Mar 10, 2010, 7:19:41 AM3/10/10
to iPhone Application Development Auditors
I didn't use a custom annotation view. I don't think implementing
MKAnnotation counts as a custom annotation as it only provides the
data for the annotation - co-ordinate, title and subtitle.

Overall steps for me were:
1) Create a class PhotoAnnotation which implements MKAnnotation
2) Create a subclass of UIViewController - MapViewController, with an
xib onto which I put an MKMapView in IB.
3) Have MapViewController implement MKMapViewDelegate and set the the
controller as the delegate of the map view.
4) Implement the delegate method mapViewDidFinishLoadingMap as follows
(no idea if this is the 'right' way!):
for each photo
create PhotoAnnotation
add annotation to mapView
retrieve annotationView for annotation from mapView
create disclosure button
set disclosure button as rightCalloutAccessoryView of
annotationView
release annotation
5) Implement the delegate method calloutAccessoryControlTapped as
follows:
get photo from photoAnnotation
create and push PhotoDetailViewController exactly as from
PhotoListViewController

I don't know why they suggested looking at UINavigationController to
work out how to do the last step as if your view controller is the map
delegate you can call self.navigationController. Again, perhaps I was
missing something?

Vicki

Lenny

unread,
Mar 10, 2010, 1:29:31 PM3/10/10
to iPhone Application Development Auditors
Vicki,

I've just started the map portion of the assignment, but I'm having
trouble retrieving the data from the database from my
MapViewController. I've loaded all the geo-tagged photos from Flickr
into my PersonListViewController and all the information is displaying
correctly. When I switch over to the MapViewController and call a
method in the PersonListViewController to fetch the data, it crashes
here:

[NSEntityDescription entityForName:@"Person"
inManagedObjectContext:moc]

with the error:

*** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '+entityForName: could not
locate an NSManagedObjectModel for entity name 'Person''

I just tried copying and pasting the code to fetch the data from the
PersonListViewController to the MapViewController, which doesn't crash
the application, but the fetch returns nil. From the debugger, the
moc appears to be the same in both view controllers, as it should be
since I'm accessing it from the singleton. Is there something I'm
missing to be able to access the database I've set up in the
PersonListViewController from my MapViewController.

Thanks,
Lenny

tda95lex

unread,
Mar 11, 2010, 4:07:47 AM3/11/10
to iPhone Application Development Auditors
The error is because it can not find model for "Person", the "Person"
should be the same name as the model in coredata and the generated
class name from coredatamodel.
I have used the same fetch from PersonListViewController in may
MapViewController but i fetch
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id
<MKAnnotation>)annotation
and i use a predicate for the name of the photo, and here i put the
photo on the map.
and I fetch firs when I add annotation on the map and i test if the
photo has coordinate for longitude and latitude.
Today i will tray to push another view when the user tap on the
annotation(i display the real photo not a pin).

Lenny

unread,
Mar 11, 2010, 2:31:35 PM3/11/10
to iPhone Application Development Auditors
tda95lex - thanks, but the spellings are correct. I even copy and
pasted the code from the working view controller. Anyways, I got
around it by creating an ivar in the app delegate and passing the
fetched array to it so that I could continue on with this assignment.
I'm sure it's something pretty obvious in setting it up (hence the
hint in the assignment about recalling how you set up core data
previously), but I just can't see it. In the future, I would create
my project with the core data check mark ticked, rather than trying to
retro-fit it in.

Vicki - "walk in the park"... until you get to the annotation part. I
purposely didn't read your walkthrough so that I could try it on my
own first. In the end, I basically did the same thing you did with
these minor differences:

1. I implemented the annotations in the viewWillAppear method instead
of mapViewDidFinishLoadingMap. I think yours make more sense.
2. I couldn't tell from your walkthrough where you created the
disclosure button. It looks like you did it in
mapViewDidFinishLoadingMap. I created mine in the
mapView:viewForAnnotation delegate, which was simple to do.

For me, I thought the hardest part was trying to figure out how to
pass the image binary to reuse PhotoDetailViewController when the
disclosure button was clicked.

redbirdo

unread,
Mar 11, 2010, 4:03:36 PM3/11/10
to iPhone Application Development Auditors
Lenny

Yeah, that annotation part was tricky! Documentation there seems
rather lacking to me....

I'd love to know how you added the disclosure button in
viewForAnnotation. I tried to do it in there but I couldn't get it to
work. I tried calling [mapView viewForAnnotation] in there and got
nil, not unsurprisingly, which is why I did it in the other method. I
also tried creating my own MKPinAnnotationView and got a pin on the
map but nothing happened when I clicked on it, so I was clearly
missing something. Send me a direct reply if you don't want to post
the code.

I found the disclosure button part fairly straightforward, as I
noticed that funny callback method on the delegate in the lecture
notes. It would never have occurred to me to look there though!

Vicki

Denis_Irl

unread,
Mar 21, 2010, 5:35:48 AM3/21/10
to iPhone Application Development Auditors
Guys a great code the the MKAnnotation...
Really helped me alot.

http://spitzkoff.com/craig/?p=81

Reply all
Reply to author
Forward
0 new messages