【发布时间】:2011-04-03 15:14:00
【问题描述】:
我在模拟器上苦苦挣扎,但最近,我直接在设备 (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? -
我做了,如果没有附加它就不会被实现,当视图加载时它会退出应用程序:)
-
好的,我刚刚在 IB 中检查了它,它已附加到我的文件所有者 :)
标签: iphone objective-c geolocation