当跨度改变时,MKCooperativeregion 的中心也会改变 - iphone
我有一个名为区域的 MKCooperativeregion。我想改变这个区域的跨度而不改变它的中心。我正在使用以下方法来更改缩放。
-(void) changeZoom
{
NSLog(@"before zoom span, center are %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
region.span.latitudeDelta = current_factor ;
region.span.longitudeDelta = current_factor ;
region.center.latitude = mymap.centerCoordinate.latitude ;
region.center.longitude = mymap.centerCoordinate.longitude ;
[mymap setRegion:region animated:TRUE];
NSLog(@"after zoom span, center are %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
}
日志显示:
before zoom span, center are 0.021950, 0.021950,19.068080,72.838111
after zoom span, center are 0.043901, 0.043901,19.068040,72.838154
此方法根据需要准确地设置了跨度。但我不希望中心坐标发生任何变化,因为当我缩小然后再缩小时,我最终会到达与起始位置不同的位置。
有没有什么方法可以在不改变中心的情况下进行放大和缩小?
感谢您提前提供的任何帮助。
I have a MKCoordinateregion called region. I want to change span of this region without changing it's center. I am using following method to change zoom.
-(void) changeZoom
{
NSLog(@"before zoom span, center are %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
region.span.latitudeDelta = current_factor ;
region.span.longitudeDelta = current_factor ;
region.center.latitude = mymap.centerCoordinate.latitude ;
region.center.longitude = mymap.centerCoordinate.longitude ;
[mymap setRegion:region animated:TRUE];
NSLog(@"after zoom span, center are %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
}
Log shows :
before zoom span, center are 0.021950, 0.021950,19.068080,72.838111
after zoom span, center are 0.043901, 0.043901,19.068040,72.838154
This method set's span accurately as desired.But I dont want any change in the center's coordinate, Because when I zoom out and then zoom back I end up at a location different from starting location.
Is there any method so that zoom in and out are possible without any change in center?
Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的前后中心坐标几乎完全相同,所以这应该不是问题。如果您确实想要完全相同相同的中心坐标,请在使用
setRegion:animated:
后立即调用setCenterCooperative:animated:
并传递一些保存的中心坐标。另外,对于布尔值,您应该使用
YES
而不是TRUE
:Your before and after center coordinates are almost exactly the same, so it shouldn't be a problem. If you really want the exact same center coordinates, call
setCenterCoordinate:animated:
right after you usesetRegion:animated:
and pass some saved center coordinates.Also, you should use
YES
instead ofTRUE
for booleans:您需要调整地图区域以确保纵横比适合地图视图的框架大小。
计算出具有所需中心的区域后,调整区域,
请参阅 文档。
You need to adjust the region of the map to make sure the aspect ratio fits the frame size of the map view.
Once the region with the desired center is calculated, adjust the region as,
See docs.