MKMapViewDelegate notifing when user moved the map - iphone

I use an MKMapView in my application, and implement its delegate. As with the Google Maps, I want to know when the user moved the map.
If you open the Google Maps application, and press the GPS icon the button is set to the DONE style and the map centers to your location. Whenever you move the map the icon automatically gets back to PLAIN style.
How can I do the same thing?
Best regards,
Paul Peelen

I am not sure whether this will solve your problem. But try overriding regionDidChangeAnimated: method of MKMapViewDelegate.
Doc says: This method is called whenever the currently displayed map region changes. During scrolling, this method may be called many times to report updates to the map position. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting scrolling performance.

Related

Callout within UITableView

I am looking for a iOS Music app style Callout functionality. What I mean with that is that I want to get the same kind of callout "bubble" you get when press-and-hold within the Music app on iOS5.
I have been searching for a good solution for this, but can't find it.
The closest to what I need is: Use UITableView bubble/callout like iPod app However, this user didn't share what solution he had.
The libs I have looked at are:
https://github.com/jayway/CWUIKit
https://github.com/edanuff/MonoTouchCalloutView
http://www.eidac.de/?p=183
All of these have one this in common: They are useless.
The problem with these are that they all use a static callout view using PNG images, not one with a pointer beneath. Also, they do not adapt to the size of the screen; thus the bubble gets outside of the screen.
Any suggestions on a good library which I can use to implements this within my app?
What about WEPopover?
It might be what you want.
WEPopover for iOS

Selecting a location with MapKit

Is there a best practice or common pattern for allowing users to select a precise location on a map using MapKit?
I've seen examples where a user can enter an address in a search box. But what about the case where a user doesn't know the exact address and wants to select a location from the map?
It's a bit more complex task than it seems.
Here is the guide how to detect single taps on a Web View.
I've used the same pattern to detect single taps on Map View but allowing zooming and dragging at the same time.
Hope it helps.
I would say that replicating the Maps application is close to a best practice for map applications.
You can test it for yourself; tap and hold somewhere on the map and a pin that you can move around by dragging will be dropped where you held your finger.
The Google Maps app seems to tackle what is a reasonable idea by touching the map by instead allowing you to drop a pin on the map; the SO post might help out.

MkMapView drop a pin on touch

I am struggling to unearth a standard way to drop a pin on a MkMapView based on a touch input. There probably isnt a standard way, but it is always worth asking. If I have to implement this myself is the best approach to add a Gesture Recogniser to pick up a tap on the map view.
Yes, you can use a UILongPressGestureRecognizer to do this.
This previous answer of mine has details with sample code:
How to add a push pin to a MKMapView(IOS) when touching?
To animate the drop, in viewForAnnotation, return an MKPinAnnotationView with animatesDrop set to YES.
I know that the Maps app has a separate button (under the curl of the map) that drops a pin. Hence that is kind of how I do it (though not under the map curl). I have not read anywhere that there is a standard but I have not read all 12,000 GB of documentation (ha ha). I would say to check out some of the "standard" apps like Maps and follow what they do just to be consistent. I know that typically a double tap zooms the map so I'm not sure that I would use that. Just my $0.02...

MKMapView reload/refresh on 3.1.2 and upwards

I know many people have had the similar issues and some have sorted them and others not. Basically I need some way to refresh the map ie get a callback to mapViewDidFinishLoading. If the location displayed has already been seen by the user it seemd the map is loaded from the cache and doesnt call mapViewDidFinishLoading which I need it to do because this fires some of my game code. Does anyone know how to do this on ios 3.1.2 and upwards? [Something along the lines of [mapView reload] (if only it were so simple).
Many thanks
Jules
I suppose the map's loading is triggered by the user dragging the map so you could use the mapView:regionDidChangeAnimated: callback and include your game code in it.
Don't know if you still need this, but I had a similar problem with viewForOverlay not being called. Actually it eventually got called, but too late for what I needed.
using the following it updated when I needed it to -
[self.map setVisibleMapRect:myMapRect];

How can I use MKPinAnnotationView on top of a regular UIView (instead of on a map)

I'm writing an iPhone application that will contain a custom map -- my own image for the map, not Google's. The image isn't very large, so instead of using a library such as RouteMe, I'm opting for just a UIScrollView with an embedded image (the map).
My question is: it is possible to re-use Apple's MKPinAnnotationView classes on top of my custom UIView so that the pin interactions will feel the same as MapKit? I have so far figured out how to add a pin to my map and position it, but I can't figure out how to let the user interact with it -- i.e. make the description bubble pop up.
Any thoughts? Thanks very much.
You might be able to make one and use add subview in order to display it, ull prolly have to do some work to get it to display where u want it to since the coordinates u give are meant to work eith mkmaps
Have you looked at this method from MKAnnotationView:
(void)setSelected:(BOOL)selected animated:(BOOL)animated
It's the only method that is publicly exposed that may show/hide the callout bubble. Other than that, you'd have to reverse engineer the classes and start poking around.
However, I would highly recommend against reverse engineering the classes and using methods that aren't publicly exposed. Apple makes no promises on maintaining backwards compatibility and if they figure out that you are using private methods, they'll kick your app from the store.
btw, full disclosure, these are Apple's documentation notes for setSelected:animated:
Discussion
You should not call this method
directly. An MKMapView object calls
this method in response to user
interactions with the annotation.