Код пользователя после:
Первый доступ следующих делегатов к вашему интерфейсу:
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface StoresMapView : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
Затем In .m используйте Подписку
Редактировать:
-(void)setMapCenter:(CLLocationCoordinate2D)location
{
NSLog(@"Current Location : %f, %f",location.latitude,location.longitude);
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.01;
span.longitudeDelta=0.01;
region.span=span;
//location.latitude=(float *)(self.appDelegate.currentLocationLatitude);
//location.latitude=self.appDelegate.currentLocationLongitude;
region.center=location;
[self._mapView setRegion:region animated:TRUE];
[self._mapView regionThatFits:region];
}
#pragma mark -
#pragma mark Location Manager functions
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"Inside Location Delegate = %@", newLocation.coordinate);
[self._mapView selectAnnotation:[[self._mapView annotations] lastObject] animated:YES];
[self setMapCenter:newLocation.coordinate];//Call this Metod defined above
[self.locationManager stopUpdatingLocation];//Don't use this line if u want continous updation in user's location
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"ERROR");
}