在MKCoordinateRegion稍微放大? [英] Slight zoom on MKCoordinateRegion?

查看:117
本文介绍了在MKCoordinateRegion稍微放大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在缩放一个MKMapView以适应一系列引脚的边界区域,但是当显示引脚时,我注意到缩放可以理想地做一个更紧。我建议的解决方案是使区域三角洲略小:

  //小ZOOM 
region.span。 latitudeDelta =(upper.latitude-lower.latitude)* 0.9;
region.span.longitudeDelta =(upper.longitude - lower.longitude)* 0.9;但是我注意到,微调没有转化为小的变焦增加,是有的一些形式的捕捉放大?真的很小的值工作,真的很大,但只是调整区域大小百分之几似乎不工作与视图几乎总是跳跃/放大到远,并剪裁我的针。



EDIT:



快速测试显示区域上不同缩放系数的结果:

  // SCALE FACTOR 
// V
region.span.latitudeDelta =(upper.latitude - lower.latitude)* 0.9;
region.span.longitudeDelta =(upper.longitude - lower.longitude)* 0.9;

以下是结果:




  • x0.5区域太小,屏幕上有一些注释

  • x0.6与使用1.0相同

  • x0.7相同如使用1.0

  • x0.8与使用1.0相同

  • x0.9与使用1.0相同

  • x1.0原始适合

  • x1.1区域过大,注释在屏幕上过小



我的观点是,非常小的调整(例如0.6到0.9)似乎没有任何区别。

解决方案

将永远不会使地图缩放级别更改。当您传递区域时,mapview会决定要使用最佳拟合的缩放级别。它永远不会使用中间级别。原因是中间缩放级别看起来模糊。你给它想要显示的区域,它使得缩放级别包括整个区域。给你想要的区域 regionThatFits:应该返回它使用的级别。



如果你缩放地图您可以达到两个缩放级别之间的级别,但如果您双击(放大)或进行2指按钮(缩小),您将只能看到标准缩放级别。 / p>

我在这里谈论缩放级别,但是它们在iOS中并不存在,就像它们在Google地图中一样。



由于您的问题,获得最适合的针脚,我发现在iOS 4中有所变化,并且我用来适应引脚的代码突然给了太多的空间。我把三角洲分为3,它再次工作。

  region.span.longitudeDelta =(maxCoord.longitude  - minCoord.longitude)/ 3.0; 
region.span.latitudeDelta =(maxCoord.latitude - minCoord.latitude)/ 3.0;

查看您的代码,您使用 * 0.9 获得完全相同的东西。



我发现的一个奇怪的事情是 regionThatFits返回的值:并不总是mapview结束设置的区域。这可能是一个错误,但它一直在那里从iOS 4.0。您可以通过记录 MKCoordinateRegion regionThatFits:并在缩放后将其与mapview的区域进行比较来自己测试。我似乎记得它在苹果开发者论坛上。


I am zooming an MKMapView to fit the bounding region of a collection of pins, however when the pins are displayed I have noticed that the zoom could ideally do with being a little tighter. My proposed solution to this was to make the region deltas slightly smaller:

// SMALL ZOOM
region.span.latitudeDelta = (upper.latitude - lower.latitude) * 0.9;
region.span.longitudeDelta = (upper.longitude - lower.longitude) * 0.9;

However I have noticed that fine adjustments don't seem to translate to a small zoom increase, is there some form of snapping on the zoom? Really small values work, as do really big ones, but just adjusting the region size by a few percent does not seem to work with the view nearly always jumping/zooming in to far and clipping my pins.

EDIT:

Quick tests showing the results of different scaling factors on the region:

 //                                                             SCALE FACTOR
 //                                                                  V
 region.span.latitudeDelta  =   (upper.latitude - lower.latitude) * 0.9;
 region.span.longitudeDelta = (upper.longitude - lower.longitude) * 0.9;

Here are the results:

  • x0.5 region too small, some annotations off screen
  • x0.6 Same as using 1.0
  • x0.7 Same as using 1.0
  • x0.8 Same as using 1.0
  • x0.9 Same as using 1.0
  • x1.0 Original fit
  • x1.1 region too big, annotations too small on screen

My point is that very small adjustments (e.g. 0.6 to 0.9) don't seem to make any difference.

解决方案

Smaller adjustments will never make the mapview zoom level change. When you pass a region, the mapview decides on what zoom level to use for the best fit. It will never use an "in-between" level. The reason is that the "in-between" zoom levels look fuzzy. You give it the region you want to show and it makes a zoom level that includes that whole region. Giving your desired region to regionThatFits: should return the level that it uses.

If you're zooming the map with a pinch, you can get to a level between two zoom levels, but if you double-tap (to zoom in) or do a 2-finger tap (to zoom out) you will only see the "standard" zoom levels.

I'm talking about zoom levels here, but really they don't exist in iOS in the same way they exist in Google Maps. Only regions exist as far as setting the map to a certain level.

With your problem of getting the best fit for pins, I found that something changed in iOS 4, and the code I'd used to fit pins suddenly gave too much space. I divided the deltas by 3 and it worked again. You might want to wrap this in a conditional to target only iOS 4.

region.span.longitudeDelta = (maxCoord.longitude - minCoord.longitude) / 3.0;
region.span.latitudeDelta = (maxCoord.latitude - minCoord.latitude) / 3.0;

Looking at your code, you use * 0.9 to get the exact same thing.

One of the strange things I found was that the value returned by regionThatFits: wasn't always the region that the mapview ended up setting. It might be a bug, but it's been there since iOS 4.0. You can test this yourself by logging the MKCoordinateRegion from regionThatFits: and comparing it to the mapview's region after zooming. I seem to remember it coming up on the Apple Developer Forums.

这篇关于在MKCoordinateRegion稍微放大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆