Iphone MapKit-调用了didUpdateToLocation,但未更新userLocation

Iphone MapKit-调用了didUpdateToLocation,但未更新userLocation,iphone,gps,mapkit,cllocationmanager,Iphone,Gps,Mapkit,Cllocationmanager,我有一个MKMapView,配置如下: mapView = [[MKMapView alloc] init]; [mapView setMapType:MKMapTypeStandard]; [mapView setShowsUserLocation:YES]; [mapView setDelegate:self]; 然后初始化CLLocationManager并调用startUpdatingLocation 我正在使用将GPS数据从手机发送到模拟器,该模拟器似乎正在工作,因为使用正

我有一个MKMapView,配置如下:

mapView = [[MKMapView alloc] init];     
[mapView setMapType:MKMapTypeStandard];
[mapView setShowsUserLocation:YES];
[mapView setDelegate:self];
然后初始化CLLocationManager并调用startUpdatingLocation

我正在使用将GPS数据从手机发送到模拟器,该模拟器似乎正在工作,因为使用正确的GPS坐标调用了CLLocationManager委托方法。然而,MKMapView从未将蓝点移离Cupertino

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

NSLog(@"Did Update Location = %f / %f", [newLocation coordinate].latitude, [newLocation coordinate].longitude);

NSLog(@"Current User Location = %f / %f", [[mapView userLocation] coordinate].latitude, [[mapView userLocation] coordinate].longitude);

}
上述方法输出以下内容:

>>> Did Update Location = 40.740100 / -73.989900 # Correct
>>> Current User Location = 37.331693 / -122.030457 # Cupertino... Incorrect
即使我使用以下方式手动更新userLocation的坐标:

[[mapView userLocation] setCoordinate:[newLocation coordinate]];

圆点仍然只是坐在库比蒂诺上。我遗漏了什么吗?

CLLocation MANAGER的问题是缓存旧位置,然后在某个时间返回旧位置。要获得一个新位置,只需检查CLLocation对象的时间戳,如果它早于时间限制,则忽略此位置

-(void) locationManager:(CLLocationManager*)manager
    didUpdateToLocation:(CLLocation*)newLocation
    fromLocation:(CLLocation*) oldLocation
{
    NSDate* time = newLocation.timestamp;
    NSTimeInterval timePeriod = [time timeIntervalSinceNow];
    if(timePeriod < 2.0 ) { //usually it take less than 0.5 sec to get a new location but you can use any value greater than 0.5 but i recommend 1.0 or 2.0
        [manager stopUpdatingLocation];
        // process the location
    } else {
        // skip the location
    }
}
-(无效)locationManager:(CLLocationManager*)manager
DidUpdateLocation:(CLLocation*)newLocation
fromLocation:(CLLocation*)oldLocation
{
NSDate*time=newLocation.timestamp;
NSTimeInterval timePeriod=[time IntervalencesEnow];
如果(timePeriod<2.0){//通常需要不到0.5秒的时间来获取新位置,但您可以使用任何大于0.5的值,但我建议使用1.0或2.0
[管理器停止更新位置];
//处理位置
}否则{
//跳过该位置
}
}
圆点仍然只是坐在库比蒂诺上。我错过什么了吗


你在模拟器上测试这个吗?请注意,在模拟器中,位置点始终保持在Cupertino中。在一个设备上试试——也许你根本没有bug

如果您阅读了问题,您将看到我正在使用iSimulate将GPS数据从手机发送到sim卡。长话短说这似乎是iSimulate软件+SDK的一个bug。它永远不会进入循环,你永远不会得到新的位置,只要检查一下就可以了。。。