我已经进入了ios的mapkit和corelocation。我只是试图显示地图并放大当前位置。我可以用我的位置绘制地图。我可以得到我目前的位置。我无法将位置数据导入地图方法。我有点小事,但认为我知道我在做什么,直到这一点! :)任何帮助表示赞赏。我的代码在这里,哪些作品,但在大西洋中间,0和0 lat!与ObjC和MapKit CoreLocation卡在一起
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
[locationManager setPurpose:@"What use is a nav app if it doesn't know where you are?!?"];
[locationManager setDelegate:self ];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[locationManager setDistanceFilter:10];
[locationManager startUpdatingLocation];
mapView=[[MKMapView alloc] initWithFrame:self.view.bounds];
[self.view insertSubview:mapView atIndex:0];
mapView.showsUserLocation = TRUE;
mapView.mapType = MKMapTypeStandard;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D location = mapView.userLocation.coordinate;
MKCoordinateRegion region;
region.span=span;
region.center=location;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[self.view insertSubview:mapView atIndex:0];
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D here = newLocation.coordinate;
NSLog(@"%f %f", here.latitude, here.longitude);
[locationManager stopUpdatingLocation];
}
您是使用模拟器还是实际的设备? –
我在两者上都试过。完全相同的结果,仅在模拟器上的位置显示为Cupertino。 iPhone上的位置显示伦敦。不知道如何让我的当前位置坐标进入地图。 – Hoppo
对不起,也许这只是我,但我完全不明白这个问题 - 你的位置显示在地图上,但你不能得到地图的方法?它在哪里返回(0,0)? – fbrozovic