我正在创建一个按钮,将一个引脚放在用户的当前位置。但是当我按下它时,而不是放在非洲周围的全球地图中间,我相信这是因为在原始教程中我得到了这个,他们创建了一个带有“ didUpdateUserLocation “但是我可以想办法将这个添加到IBAction中,这就是我正在使用的东西。有没有人遇到过这个问题?
这是放大代码,但请注意 didUpdateUserLocation 向下vvvv
-(void)mapView: (MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
MKCoordinate region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate,
800,800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:NO];
}
`
现在,这里是IBAction,当点击时,在非洲或全球地图的中心放下针脚。我认为这是因为它缺少 didUpdateUserLocation
-(IBAction)addAnnotation;
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate,
800,800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:NO];
MKPointAnnotation *point = [[MKPointAnnotation Alloc] init];
point.coordinate = myLocation.coordinate;
point.title = @"Test";
point.subtitle = @"Text";
[self.mapView addAnnotation:point];
}
因此,如果有人知道如何,我认为是解决方案,didUpdateUserLocation到IBAction,请让我知道,欣赏它!
答案 0 :(得分:0)
试试这个......
- (void)mapView:(MKMapView *)aMapView didUpdateUserLocation:(MKUserLocation *)aUserLocation
{
MKCoordinateRegion region;
CLLocationCoordinate2D location;
location.latitude = aUserLocation.coordinate.latitude;
location.longitude = aUserLocation.coordinate.longitude;
region.span = aMapView.region.span;
region.center = location;
[self.objMapView setRegion:region animated:FALSE];
showCurrentLoc = FALSE;
}
-(IBAction)addAnnotation;
{
MKCoordinateRegion region;
region.span = self.mapView.region.span;
region.center = location;
[self.mapView setRegion:region animated:FALSE];
MKPointAnnotation *point = [[MKPointAnnotation Alloc] init];
point.coordinate = self.mapView.userLocation.coordinate;
point.title = @"Test";
point.subtitle = @"Text";
[self.mapView addAnnotation:point];
}