【问题标题】:core location proplem in simulator模拟中的核心定位问题
【发布时间】:2012-10-23 09:36:39
【问题描述】:

我无法在 iphone 模拟器中获取当前位置。我将自定义位置设置为埃及的纬度和经度,但没有获得当前位置。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //Make this controller the delegate for the map view.
    self.MapView.delegate = self;     

    // Ensure that you can view your own location in the map view.
    [self.MapView setShowsUserLocation:YES];



    //Instantiate a location object.
    locationManager = [[CLLocationManager alloc] init];
    [locationManager startUpdatingLocation];

    //Make this controller the delegate for the location manager.
    [locationManager setDelegate:self];

    //Set some parameters for the location object.
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}

这是委托:

#pragma mark - MKMapViewDelegate methods.

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views 
{    
    MKCoordinateRegion region;
    region = MKCoordinateRegionMakeWithDistance(locationManager.location.coordinate,2000,2000);


    [mv setRegion:region animated:YES];
}

请任何人帮助我。

【问题讨论】:

    标签: iphone objective-c ios mapkit core-location


    【解决方案1】:

    到底是什么问题?没有获得您应该拥有的 userLocation 或没有将地图区域移动到正确的位置?

    如果是第一个,那主要是工具问题,而不是代码问题:

    如果您的位置在项目内的 gpx 文件中,您应该可以通过编辑方案/选项/允许位置模拟/并选择默认位置来开始它

    您的项目中应该有一个 DemoStart.gpx 文件,如下所示:

    <?xml version="1.0"?>
    <gpx version="1.1" creator="Xcode">
        <wpt lat="20.88072" lon="10.67429">
            <name>Demo Starting Location</name>
        </wpt>
    </gpx>
    

    (抱歉,我懒得找埃及的准确坐标)。

    【讨论】:

    • 我的 iPhone 模拟器 5.0 版在哪里可以找到这个窗口?
    • 在 Xcode(不是模拟器)中,您可以通过单击窗口左上角的两部分下拉列表来编辑方案。或者您可以按屏幕底部附近的位置服务图标(跳过、进入、退出旁边的箭头)
    【解决方案2】:

    您必须首先确保您的 CLLocationManager 将他的位置更新为您的位置。为此,将视图控制器设置为 CLLocationManager 的委托,您已经这样做了,并保存此位置。完成所有设置后尝试调用startUpdatingLocation,并将showsUserLocation 设置为YES

    - (void)locationManager:(CLLocationManager *)manager
    
         didUpdateLocations:(NSArray *)locations {
    
        // If it's a relatively recent event, turn off updates to save power
    
        CLLocation* myLocation = [locations lastObject];
    }
    

    请确保您在 iOS 模拟器版本 >= 5.1 上进行测试

    【讨论】:

      猜你喜欢
      • 2010-11-12
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 2019-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多