(iPhone) how to implement draggable pins using OS 4.0 MapKit? - iphone

Can anyone provide any sample code/instructions for implementing draggable pins in OS 4.0 using the MapKit framework?

Sure thing buddy (yes I'm talking to myself),
In your custom annotation add:
#property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;
This satisfies the requirement of implementing setCoordinate, as mentioned inhttp://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html#//apple_ref/occ/instp/MKAnnotationView/draggable
In your MapView delegate add:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
//..Whatever you want to happen when the dragging starts or stops
}
and in your AnnotationView set draggable to true, so for example:
customAnnotationView.draggable = YES;
I think that was everything that I did to get it working. Tell me if you have troubles.

Check out MapKitDragAndDrop by Ching-Lang Huang and the author's accompanying blog post.

Related

Detect whether map has been scrolled or not in mapview

How can I detect whether map has been scrolled or not in mkmapview in ios. The delegate method of map is not getting called. please help..
Use
-(void)mapView:(MKMapView *)mapView1 regionDidChangeAnimated:(BOOL)animated
Also make sure your mapView.delegate = self;

Add Zooming to UIScrollView

I've been doing the tutorials in the Big Nerd Ranch Iphone development book and ran into an issue I can't solve or find an answer for.
The App (Hypnosister) basically just draws a bunch of concentric circles and places some text on the screen using the DrawRect method. I got that to work and I was able to add scrolling ot the view but can't add the ability zoom. I've checked my code 100 times and can't figure it out. I think they used an earlier version of the OS and I am using 4.2. Did something change? Can you find the issue?
Here is the relevant code:
#interface HypnosisterAppDelegate : NSObject <UIApplicationDelegate,
UIScrollViewDelegate>
{
UIWindow *window;
HypnosisView *view;
}
and this goes in the application didFinishLaunchingWithOptions part:
[[UIApplication sharedApplication]
setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
and method gets called after that method closes:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return view;
}
HypnosisView is a UIView class that does the drawing. Thanks for the help.
Just downloaded the examples for the book from the Big Nerd Ranch website and it works fine on the simulator under 1OS 4.3. Did you add these lines of code to didFinishLaunchingWithOptions:
// Enable zooming
[scrollView setMinimumZoomScale:0.5];
[scrollView setMaximumZoomScale:5];
[scrollView setDelegate:self];
This is only possible problem I can think of based on the code you've shown.

how to handle navigation on map annotation bubble

I trying to create an application which will show some location on map. When i click on bubble with location name, i want to navigate to different view which will some information regarding the selected location
Can anyone guide me how to do that..
Thanx
#Umang why don't to you try adding a UIButton to the MKPinAnnotationView and give it a action that will be much easier. Navigate to diffetrent view by the action of UIButton......Please have a look on this tutorial and see how the UIImageView and UIButton is added to the MKPinAnnotationView
good Luck!
You can use MKMapView delegate method
- (void) mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control {
// navigate to view from here
}

Detect iPhone device capabilities for Core Location

I have a core location app that I'm writing leveraging the startMonitoringSignificantLocationChanges method to generate updates when appropriate but this does not work on older devices such as iPhone 3g.
I would like for the core location functionality to still work while the device is open, so I thought I could use a selector test to see if the device supports the method, and if it doesnt just use the standard core location updating method. Although this selector doesnt work on my iphone 3g, it still uses startMonitoringSignificantLocationChanges even though it doesnt work on the phone.
Any ideas? I would rather not use the device identifier tests because then it will have to be updated for every future release of the phone.
#interface RootViewController : UITableViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
#property (nonatomic, retain) CLLocationManager *locationManager;
#implementation RootViewController
#synthesize locationManager;
if([locationManager respondsToSelector:#selector(startMonitoringSignificantLocationChanges)]) {
[locationManager startMonitoringSignificantLocationChanges];
NSLog(#"Using bg updates");
}
else {
[locationManager startUpdatingLocation];
NSLog(#"Using reg updates");
}
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
…
}

MKMapView didUpdateUserLocation not updating

I have an application with map and want to zoom to the current location, when it's updated.
I use -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation delegate method to know when user location was updated.
Now on simulator method is being called as it should. But when i test it on device (iphone 2g) the location is updated on map, but "didUpdateUserLocation" method is not being called at all, same for delegate method "mapViewWillStartLocatingUser".
The system asks if I allow to get my location for app and starts showing my location, but
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
NSLog(#"didUpdateUserLocation = '%#'", userLocation);
}
is never called.
Reference mentions that this delegate method is available since iOS 4.0. Your simulator is most probably running iOS 4.0 while your phone - iOS 3.1.
I'm having the same problem and still looking for solution. Perhaps accessing CL methods directly will help.
try this Map.showsUserLocation=YES;