Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在模拟器上获取用户MapKit的u正确坐标_Iphone_Ios_Xcode_Mapkit - Fatal编程技术网

Iphone 在模拟器上获取用户MapKit的u正确坐标

Iphone 在模拟器上获取用户MapKit的u正确坐标,iphone,ios,xcode,mapkit,Iphone,Ios,Xcode,Mapkit,情况如下,我在MacOS 10.7上运行xCode 4.1,启动iPhone模拟器并使用MapKit,我试图获得真实的用户坐标。。。默认用户的位置在美国库比蒂诺。。。要获得这一点的坐标,我使用: self.mapView.userLocation.location.coordinate 。。。但这让我走到了地图的中心(在非洲) 问题1:为什么???为什么用户的pin设置为Cupertino,但其坐标在非洲是(纬度:0,经度:0) 。。。然后 我已将控制器设置为CCLocationManager

情况如下,我在MacOS 10.7上运行xCode 4.1,启动iPhone模拟器并使用MapKit,我试图获得真实的用户坐标。。。默认用户的位置在美国库比蒂诺。。。要获得这一点的坐标,我使用:

self.mapView.userLocation.location.coordinate
。。。但这让我走到了地图的中心(在非洲)

问题1:为什么???为什么用户的pin设置为Cupertino,但其坐标在非洲是(纬度:0,经度:0)

。。。然后

我已将控制器设置为CCLocationManagerDelegate和MKMapViewdelegate,并已将控制器初始化为CCLocationManagerDelegate事件的委派。。。但是这两个委托方法都没有被调用

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

谢谢,Art

模拟器中的默认位置是Cupertino。在最新的Xcode(我相信是4.2)中,您可以从预先填充的位置菜单中设置模拟器的位置(您只需在项目中包含一个GPX文件即可添加自己的位置)


如果您在设备上运行并为应用程序启用位置服务,则应使用代码获取有效位置。

让我澄清我的问题。。。 据我所知,不管怎样,用户位置在模拟器上似乎为零。。。好啊但第二个问题是为什么不调用CLLocationManagerDelegate方法“didUpdateToLocation”? 我看过这个教程,它应该在模拟器上调用。。。 那么我做错了什么? 同时,我在日志中看到这样的错误——“服务器不接受客户端注册” 这是否就是不调用位置委托的原因

更新:

我在xCode 4.3上试过这个,但仍然不起作用。。。 在第一次调用userLocation时,它在第二次(-180,-180)时返回(0,0)

然后我切换到IOS 5 SDK,现在Map根本没有加载,出现错误-
\uu georgisternetworkdefaults\u block\u invoke\u 0:无法连接到com.apple.geod.defaults上的geod

更新:


卸载所有xCode版本,然后安装稳定的4.2版本确实有帮助已解决

好的,我知道Cupertino是预设位置,但为什么蓝色用户标记在Cupertino和mapView中。userLocation在非洲?为什么它们不同?@Art检查mapView.userLocation是否为
nil
。我没有答案。您是否在设备上或在Xcode 4.2中尝试过(将位置设置为非Cupertino)?@XcodeDev怎么说。我认为模拟器在Xcode 4.2之前没有“启用”位置服务,因此您得到的位置为零(即使它在CUP中显示位置)。。。第一次调用时userLocation如下-纬度:2.99608857886808235E-282,经度:1.6178140217591351e-303,然后我设置mapView参数(包括showUserLocation)并在第二次调用时获得以下值-纬度:2.5498006923989488e-301,经度:1.22568035597691E-282…如果
self.mapView.userLocation.location.coordinate
给你0,0,可能是因为mapView或userLocation或location是一个零指针。很好的信息。顺便说一句,如果最终要安装Xcode 4.3 beta版,请确保将其安装在与4.2安装不同的目录中。
//@interface MapController : UIViewController<CLLocationManagerDelegate, MKMapViewDelegate> 

//@property (nonatomic, retain) MapModel *mapModel;
//@property (nonatomic, retain) IBOutlet MKMapView *mapView;

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{ ... }

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{ ... }

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{ ... }

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.mapModel = [[[MapModel alloc] init:self] autorelease];

    [self.mapView setShowsUserLocation:YES];
    [self.mapView setZoomEnabled:YES];
    [self.mapView setScrollEnabled:YES];
    [self.mapView setMapType:MKMapTypeStandard];

    CLLocationCoordinate2D x = 
        self.mapView.userLocation.location.coordinate; // (0,0) why???

    //[self.mapView setRegion:xx animated:YES];
    //[self.mapView regionThatFits:self.mapModel.region];
    [[self.mapView userLocation] setCoordinate:[x coordinate]];
}

...
   //@property (nonatomic, copy) NSString *user;
   //@property (nonatomic, copy) NSString *caption;
   //@property (nonatomic, copy) NSString *description;
   //@property (nonatomic, assign) MKCoordinateRegion region;
   //@property (nonatomic, retain) CLLocationManager *manager;

    - (id)init :(id)delegate
    {
        self.manager = [[[CLLocationManager alloc] init] autorelease];

        self.manager.delegate = delegate;
        self.manager.distanceFilter = kCLDistanceFilterNone;
        self.manager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
        [self.manager startUpdatingLocation];

        MKCoordinateRegion region = {{0, 0}, {0.2, 0.2}};

        self.region = region;

        return self;
    }