I need to diaplay user current location in map with blue dot circle. I used CLLocationManager. But mapview only displayed. I sent custom lat,long. But this lat,long can't displayed in map.
Code:
- (void)viewDidLoad
{
UIView *vc=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:vc];
MKMapView *map = [[MKMapView alloc] init];
map.frame = CGRectMake(0, 0, 320, 480);
map.showsUserLocation=YES;
[self.view addSubview:map];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
// NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
CLLocationCoordinate2D loc = [newLocation coordinate];
NSLog(@"current longitude = %f , current latitude = %f",loc.longitude,loc.latitude);
}
Use InterfaceBuilder, drop a map view onto your screen, tick the box next to shows user location.
Also, you don't need a locationmanager for showing the user location, the mapview will take care of that.