MkMapView drop a pin on touch - iphone

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...

Related

How to use UIPinchGestureRecognizer

I have made a simple web browser for the iPhone but I would really like to be able to pinch to zoom in and out with the UIPinchGestureRecognizer, but I don't know how to use it. Could someone explain to me how to implement it in my code? If you have a link to a good explanation of this that would be very much appreciated as well.
Why do you need to implement it at all? UIWebView already supports pinch-zooming natively.
For all the stuff you need for gesture recognizer's, look here. Basically, you set up a gesture for your view, and add a selector method that would get called if the view recognizes that gesture. In this case, when it detects a pinch, you would tell the view to change size to your liking.
This, however, is the hard way of doing it though, as the pinch gesture is already associated with a UIWebView (not to mention, the MKMapView as well). You should probably look at this other post to see what you need to do. Any search on google will also point you in the right direction. Hope that helps!

custom MKAnnotationView

I have been trying to create a MKAnnotationView which has to display multiple line of text.
Some one has pointed me to do things said in the below url
How to add more details in MKAnnotation in iOS
But i am not sure how to attain it due to my small knowledge in iPhone programming..
i have searched for a long tme but no use ...
Looking for help...Please guide me ..
Just to clarify, and based on what you are saying, you want to customise the look of the CALLOUT bubble that shows title/subtitle, not the annotation view itself, is this correct?
In case you're not clear, the MKAnnotationView is basically the image/icon/button that you see on top of the map for a specific location. Once you tap on that image/icon, if enabled, a call out bubble will appear where you can set a view for the left hand side, title, subtitle and a view for the right hand side - is this what you are hoping to customise?
If that's the case, this is a non-trivial task and if you are new to iPhone development chances are this is going to take a long time for you to implement.
If you still want to have a look, here's a blog post that might be of interest to you... http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/
Here is another demonstration of customizing the callout bubble of an MKAnnotationView.

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.

MKMapViewDelegate notifing when user moved the map

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.

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.