Я борюсь с геолокацией на симуляторе, но недавно я проверил его непосредственно на устройстве (iPhone), но осталась та же проблема, вот что я получил, когда мое приложение заканчивает запуск, и код геолокации должен дать мнеместоположение на карте (помните, что изображение выше для моего приложения на iPhone, а не с симулятором):
поэтому для моего кода мое приложение на самом деле имеет много просмотров, но что касается этой функции, я работал над appdelegate (.m и .h) и над представлением, касающимся отображения местоположения на карте (PositionActuelleViewController).
appdelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sleep(3);
// Override point for customization after application launch.
self.locationManager=[[[CLLocationManager alloc] init] autorelease];
if([CLLocationManager locationServicesEnabled]) {
self.locationManager.delegate=self;
self.locationManager.distanceFilter=100;
[self.locationManager startUpdatingLocation];
}
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
и в том же файле после метода dealloc:
#pragma mark CLLocationManagerDelegate Methods
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
MKCoordinateRegion region;
region.span=span;
region.center=newLocation.coordinate;
[viewCont.mapView setRegion:region animated:YES];
viewCont.mapView.showsUserLocation=YES;
viewCont.latitude.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
viewCont.longitude.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
}
мой файл PositionActuelleViewController.m:
#import "PositionActuelleViewController.h"
@implementation PositionActuelleViewController
@synthesize mapView;
@synthesize latitude;
@synthesize longitude;
-(IBAction)goBackToMenu {
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)goToRechercherView;
{
rechercherViewController.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:rechercherViewController animated:YES];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[mapView release];
[latitude release];
[longitude release];
[super dealloc];
}
@end
Чего мне здесь не хватает?