我需要放大到一个MKMapItem,它是用NSNotification传递的,处理方式如下:
-(void)zoomToAnnotation:(NSNotification *)notification {
// Zoom into the passed MKMapItem
MKMapItem *passedMapItem = notification.object;
// self.previewMapView is the what I called my mapView
}更新:
-(void)zoomToAnnotation:(NSNotification *)notification {
// Zoom into the passed MKMapItem
NSLog(@"beginCam");
MKMapItem *passedMapItem = notification.object;
MKMapCamera *mapCamera = [[MKMapCamera alloc] init];
mapCamera.centerCoordinate = [[passedMapItem placemark] coordinate];
[self.previewMapView setCamera:mapCamera animated:YES];
NSLog(@"endCam");
}更新2:

如何使用MKMapItem放大单个MKMapView?
谢谢!
发布于 2015-01-19 03:50:34
(从聊天消息复制而来,稍微快一点脏):
所以,我们有点离谱了。不过,我通过以下方法使它发挥作用:
-(void)zoomToAnnotation:(NSNotification *)notification {
MKMapItem *passedMapItem = (MKMapItem *)notification.object;
CLLocationCoordinate2D coordinateOfInterest = passedMapItem.placemark.coordinate;
MKCoordinateRegion region = MKCoordinateRegionMake(coordinateOfInterest, MKCoordinateSpanMake(.1, .1));
[self.previewMapView setRegion:region
animated:YES];
[self.previewMapView addAnnotation:passedMapItem.placemark];
}
//in my implementation, I just have a random button call this
-(void) makeNotification{
CLLocationCoordinate2D coordinateOfInterest = self.locationManager.location.coordinate;
MKPlacemark * placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinateOfInterest
addressDictionary:nil];
MKMapItem * mapItem = [[MKMapItem alloc] initWithPlacemark:placeMark];
[[NSNotificationCenter defaultCenter] postNotificationName:@"mapPoint"
object:mapItem ];
}所以我想最大的问题是,MKCamera对象并不打算用来改变地图视图的视图,至少在我们尝试的方式中是这样的。最终,在这种情况下,调用setRegion:animated:最终会放大某个区域。我也实施了setCenterCoordinate:animated:,但我发现它似乎并没有影响我们希望达到的最终结果。
此外,需要通过CLLocationManager提供位置数据,在iOS中,这需要两个(文档很少)的操作:
NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription以及字符串描述。(见此链接可获得更多信息)requestAlwaysAuthorization和requestWhenInUseAuthorization提供通知服务无论如何,我发现google在这方面更容易使用,所以我可以回到使用它。不过,想清楚这点还是很好的。
祝其他人好运!
https://stackoverflow.com/questions/27993519
复制相似问题