缩放以适合所有注释的区域 - 最终在注释之间放大
我在将所有注释适合屏幕时遇到问题...有时它会显示所有注释,但有时应用程序会在两个注释之间放大,因此它们都不可见... 我希望应用程序始终使区域适合注释,而不是在它们之间放大...我做错了什么?
if ([mapView.annotations count] == 2) {
CLLocationCoordinate2D SouthWest = location;
CLLocationCoordinate2D NorthEast = savedPosition;
NorthEast.latitude = MAX(NorthEast.latitude, savedPosition.latitude);
NorthEast.longitude = MAX(NorthEast.longitude, savedPosition.longitude);
SouthWest.latitude = MIN(SouthWest.latitude, location.latitude);
SouthWest.longitude = MIN(SouthWest.longitude, location.longitude);
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:SouthWest.latitude longitude:SouthWest.longitude];
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:NorthEast.latitude longitude:NorthEast.longitude];
CLLocationDistance meter = [locSouthWest distanceFromLocation:locNorthEast];
MKCoordinateRegion region;
region.span.latitudeDelta = meter / 111319.5;
region.span.longitudeDelta = 0.0;
region.center.latitude = (SouthWest.latitude + NorthEast.latitude) / 2.0;
region.center.longitude = (SouthWest.longitude + NorthEast.longitude) / 2.0;
region = [mapView regionThatFits:region];
[mapView setRegion:region animated:YES];
[locSouthWest release];
[locNorthEast release];
}
有什么想法吗?
谢谢!!
I have a problem with fitting all my annotations to the screen... sometimes it shows all annotations, but some other times the app is zooming in between the two annotations so that none of them are visible...
I want the app to always fit the region to the annotations and not to zoom in between them... what do I do wrong?
if ([mapView.annotations count] == 2) {
CLLocationCoordinate2D SouthWest = location;
CLLocationCoordinate2D NorthEast = savedPosition;
NorthEast.latitude = MAX(NorthEast.latitude, savedPosition.latitude);
NorthEast.longitude = MAX(NorthEast.longitude, savedPosition.longitude);
SouthWest.latitude = MIN(SouthWest.latitude, location.latitude);
SouthWest.longitude = MIN(SouthWest.longitude, location.longitude);
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:SouthWest.latitude longitude:SouthWest.longitude];
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:NorthEast.latitude longitude:NorthEast.longitude];
CLLocationDistance meter = [locSouthWest distanceFromLocation:locNorthEast];
MKCoordinateRegion region;
region.span.latitudeDelta = meter / 111319.5;
region.span.longitudeDelta = 0.0;
region.center.latitude = (SouthWest.latitude + NorthEast.latitude) / 2.0;
region.center.longitude = (SouthWest.longitude + NorthEast.longitude) / 2.0;
region = [mapView regionThatFits:region];
[mapView setRegion:region animated:YES];
[locSouthWest release];
[locNorthEast release];
}
Any ideas?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用以下代码
Use the following code
而不是:
尝试添加:
并删除:
Instead of:
Try adding:
And removing: