locationManager:didUpdateToLocation:fromLocation:与mapView.userLocation.location

时间:2010-04-20 17:23:07

标签: iphone locationmanager

目前,我使用mapView.showsUserLocation=YES;作为显示iPhone位置的辐射蓝色图标,但不知道如何获取其背后的坐标。

我尝试使用locationManager:didUpdateToLocation:fromLocation:

的配置self.locationManager = [[[CLLocationManager alloc] init] autorelease]; locationManager.delegate = self; locationManager.distanceFilter=kCLDistanceFilterNone; //record every movement locationManager.desiredAccuracy=kCLLocationAccuracyBest; [locationManager startUpdatingLocation];

我同时尝试了yourGPS=newLocation.coordinate;  和yourGPS=mapView.userLocation.location.coordinate;didUpdateToLocation,但大部分时间我都可以看到蓝色气泡(由mapView.showsUserLocation=YES;向前移动控制,但didUpdateToLocation中记录的坐标没有变化。

我应该在哪里放yourGPS=mapView.userLocation.location.coordinate;来记录驱动蓝色气泡的坐标?

感谢您的任何信息。

2 个答案:

答案 0 :(得分:1)

这是我在我的应用中使用的内容:

- (void)center
{
    NSLog(@"Centering...");
    MKCoordinateRegion newRegion;
    newRegion.center.latitude = mapView.userLocation.location.coordinate.latitude;
    newRegion.center.longitude = mapView.userLocation.location.coordinate.longitude;        
    newRegion.span.latitudeDelta = 0.112872;
    newRegion.span.longitudeDelta = 0.109863;

    [mapView setRegion:newRegion animated:YES];
}

答案 1 :(得分:0)

因为mapView.showsUserLocation=YES;带来了内存泄漏,我已经停止使用它,只使用locationManager来获取坐标。它的缺点是我失去了可爱的蓝色泡泡,我不知道如何自己做。