Alex Rivera | Logout

How to set accuracy and distance filter when using MKMapView

Asked 2011-05-08T21:51:17.690
29

When i use setShowsUserLocation with MKMapView to track user location, how do I set the accuracy and distance filter? I am not talking about CLLocationManager.

Thanks,

Edit
Report

1 Answer

3

For displaying map here is an example code.

First import MKMapKit and CoreLocation framework in your .h file.

#import <MapKit/MapKit.h>
 #import <CoreLocation/CoreLocation.h>

Add MKMapKit and CoreLocation Delegate in .h file

@interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>


CGPoint gameMapCenter = CGPointMake([[UIScreen mainScreen] bounds].size.width / 2, [[UIScreen mainScreen] bounds].size.height / 2);
    gameMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 640, 620)];
    [gameMapView setCenter:gameMapCenter];
    [gameMapView setMapType:MKMapTypeStandard];
    [gameMapView setDelegate:self];
    [self.view addSubview:gameMapView];
    [gameMapView setShowsUserLocation:YES];

Use CLLocationManager for fetching user location.

Declare an instance of CLLocationManager

CLLocationManager *locationManager;

In ViewDidLoad

locationManager = [[CLLocationManager alloc] init];

[locationManager setDelegate:self];

[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

[locationManager setDistanceFilter:kCLDistanceFilterNone];

[locationManger startUpdatingLocation];

startUpdatingLocation Method Implementation:

(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
      //Your Stuff
}
answered 2013-02-01T08:36:34.667

Your Answer