地理位置即使在设备上也不起作用

时间:2011-04-03 15:14:01

标签: iphone objective-c geolocation

我在模拟器上挣扎着地理定位,但最近,我已经在设备(iPhone)上直接测试了它,但同样的问题仍然存在,这是我的应用程序完成启动后得到的地理定位代码假设给我的地图上的位置(请记住上面的图片是针对iPhone上的应用而不是模拟器):

enter image description here

所以对于我的代码,我的应用程序实际上有很多视图,但是关于这个函数,我已经处理了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

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

是否会调用委托方法-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation?也许如果您取消注释self.locationManager.distanceFilter=100;它会起作用,因为根据文档,distanceFilter属性定义了设备在生成更新事件之前必须横向移动的最小距离(以米为单位)。