我與模擬器地理位置奮力工作,但最近,我已經直接測試了設備(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
缺少什麼我在這裏?
我希望你不要忘記在IB中附加'mapView'? – 2011-04-03 15:20:19
我做到了,如果它沒有連接它不會被執行,它會退出應用程序時的觀點是負載:) – Malloc 2011-04-03 15:26:55
好吧,我剛剛檢查它在IB和它連接到我的文件的所有者:) – Malloc 2011-04-03 15:30:43