GMSTileURLConstructor返回缩放的奇怪数据 [英] GMSTileURLConstructor Returns Strange Data for Zoom

查看:114
本文介绍了GMSTileURLConstructor返回缩放的奇怪数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在Google Maps for iOS上使用 GMSTileURLConstructor 绘制自定义覆盖图。我使用的是 下面的代码来获取我的URL

  GMSTileURLConstructor urls = ^(NSUInteger x,NSUInteger y,NSUInteger zoom){
NSString * url = @;

for(NSDictionary * limits in [selectedPropertyMap objectForKey:@property_map_zoom_levels]){
int zoomLevel = [[限制objectForKey:@level] intValue];
int tileMinX = 0;
int tileMaxX = 0;
int tileMinY = 0;
int tileMaxY = 0;

if([limits objectForKey:@tile_min_x]!=(id)[NSNull null]){
tileMinX = [[限制objectForKey:@tile_min_x] intValue];

if([limits objectForKey:@tile_max_x]!=(id)[NSNull null]){
tileMaxX = [[限制objectForKey:@tile_max_x] intValue];

if([limits objectForKey:@tile_min_y]!=(id)[NSNull null]){
tileMinY = [[限制objectForKey:@tile_min_y] intValue];

if([limits objectForKey:@tile_max_y]!=(id)[NSNull null]){
tileMaxY = [[限制objectForKey:@tile_max_y] intValue]; ((tileMinX< = x)&&&(tileMaxX> = x)& amp;& amp;& amp; amp;(b)) ;&(tileMinY< = y)&&(tileMaxY> = y)){
url = [NSString stringWithFormat:@%@%@ /%@ /%@ /%lu_%lu (限制objectForKey:@id],(无符号长整数)x,(无符号长整数)y]; [限制objectForKey:@id]。
NSLog(@url - >%@ / zoom%lu /%i,url,(unsigned long)zoom,zoomLevel);
return [NSURL URLWithString:url];
}
}
}
return [NSURL URLWithString:url];
};

当我注销网址时,zoom和zoomLevel会得到以下信息:



2014-05-16 17:25:15.621应用程序[24491:61003] url - > < BASEURL> /16/9/19/159786_195303.png/zoom 19/19



同时,我正在记录(GMSMapView *)mapView didChangeCameraPosition :( GMSCameraPosition *)position {

   - (void)mapView: b $ b zoomLevelLabel.text = [NSString stringWithFormat:@ZL:%.2f,position.zoom]; 
NSLog(@camera changed - zoom%f,position.zoom);
[self hideMarkersBasedOnZoom:position.zoom];
if(position.zoom> 21){
GMSCameraPosition * camera = [GMSCameraPosition cameraWithLatitude:position.target.latitude longitude:position.target.longitude zoom:21];
[mapView_ setCamera:camera];
}
}

哪些日志



2014-05-16 17:25:15.640应用程序[24491:60b] camera changed - zoom 18.022364



任何人都可以解释缩放级别值的差异以及如何正确匹配吗?

一些研究,我相信Google为 GMSTileLayer 处理缩放级别的方式与相机的缩放级别不同mapView



GMSTileLayer类参考



https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_tile_layer


缩放级别为0时,整个世界是由单个瓦片覆盖的正方形,
且坐标x和y均为0为那块瓷砖。在缩放级别为1,
时,世界将被x和y为0或1的4个图块覆盖,依此类推。


对于mapView相机



https://developers.google.com/maps/documentation/ios/views#zoom


相机的缩放级别决定了地图的比例。在
更大的缩放级别上,可以在屏幕上看到更多细节,而在屏幕上可以看到更多世界上更小的
缩放级别。在
的缩放等级为0时,地图的比例尺是这样的,整个世界的
宽度大约为256分。



增加缩放在1美元的B屏幕上,世界的宽度加倍。因此,在缩放级别N处,世界的宽度大约为
256 * 2N,即在缩放级别2时,整个世界大约为1024
点宽。请注意,缩放级别不需要是整数。地图允许的
范围的缩放级别取决于包括位置,地图类型和屏幕尺寸在内的
元素数量。

GMSTileLayer 的缩放是 NSUInteger ,而 camera 的缩放是的即可。 GMSTileLayer的缩放用于确定贴图数量。根据公式 256 * 2N ,使用相机变焦确定点数



我可能是错的,但我认为这两个缩放级别都不会匹配。

没有如此相关:Google刚刚发布了iOS Maps SDK V1.8.1,它解决了与GMSTileLayer相关的问题,并修复了崩溃问题。


I am trying to draw a custom overlay on Google Maps for iOS using GMSTileURLConstructor.

I am using the following code to get my URL

GMSTileURLConstructor urls = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) {
        NSString *url = @"";

        for (NSDictionary *limits in [selectedPropertyMap objectForKey:@"property_map_zoom_levels"]) {
            int zoomLevel = [[limits objectForKey:@"level"] intValue];
            int tileMinX = 0;
            int tileMaxX = 0;
            int tileMinY = 0;
            int tileMaxY = 0;

            if ([limits objectForKey:@"tile_min_x"] != (id)[NSNull null]) {
                tileMinX = [[limits objectForKey:@"tile_min_x"] intValue];
            }
            if ([limits objectForKey:@"tile_max_x"] != (id)[NSNull null]) {
                tileMaxX = [[limits objectForKey:@"tile_max_x"] intValue];
            }
            if ([limits objectForKey:@"tile_min_y"] != (id)[NSNull null]) {
                tileMinY = [[limits objectForKey:@"tile_min_y"] intValue];
            }
            if ([limits objectForKey:@"tile_max_y"] != (id)[NSNull null]) {
                tileMaxY = [[limits objectForKey:@"tile_max_y"] intValue];
            }

            if (zoomLevel == (unsigned long)zoom) {
                if ((tileMinX <= x) && (tileMaxX >= x) && (tileMinY <= y) && (tileMaxY >= y)) {
                    url = [NSString stringWithFormat:@"%@%@/%@/%@/%lu_%lu.png", MAP_URL, [property objectForKey:@"id"], [limits objectForKey:@"property_map_id"], [limits objectForKey:@"id"], (unsigned long)x, (unsigned long)y];
                    NSLog(@"url -> %@/zoom %lu/%i",url, (unsigned long)zoom, zoomLevel);
                    return [NSURL URLWithString:url];
                }
            }
        }
        return [NSURL URLWithString:url];
    };

When I log out the URL, zoom and zoomLevel I get the following information:

2014-05-16 17:25:15.621 Application[24491:61003] url -> <BASEURL>/16/9/19/159786_195303.png/zoom 19/19

At the same time, I am logging the camera zoom when the camera changes

- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {
    zoomLevelLabel.text = [NSString stringWithFormat:@"ZL: %.2f",position.zoom];
    NSLog(@"camera changed - zoom %f",position.zoom);
    [self hideMarkersBasedOnZoom:position.zoom];
    if(position.zoom > 21) {
        GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:position.target.latitude longitude:position.target.longitude zoom:21];
        [mapView_ setCamera:camera];
    }
}

Which logs

2014-05-16 17:25:15.640 Application[24491:60b] camera changed - zoom 18.022364

Can anyone explain the discrepancy in zoom level value and how to have it match appropriately?

解决方案

After I did some research, I believe the way Google handles the zoom level for GMSTileLayer is not the same with zoom level for the camera of mapView.

GMSTileLayer Class Reference

https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_tile_layer

At zoom level 0 the whole world is a square covered by a single tile, and the coordinates x and y are both 0 for that tile. At zoom level 1, the world is covered by 4 tiles with x and y being 0 or 1, and so on.

For the mapView Camera

https://developers.google.com/maps/documentation/ios/views#zoom

The zoom level of the camera determines the scale of the map. At larger zoom levels more detail can be seen on the screen, while at smaller zoom levels more of the world can be seen on the screen. At zoom level 0, the scale of the map is such that the entire world has a width of approximately 256 points.

Increasing the zoom level by 1 doubles the width of the world on the screen. Hence at zoom level N, the width of the world is approximately 256 * 2N, i.e., at zoom level 2, the whole world is approximately 1024 points wide. Note that the zoom level need not be an integer. The range of zoom levels permitted by the map depends on a number of factors including location, map type and screen size.

The zoom for GMSTileLayer is NSUInteger while the zoom for camera is float. The zoom for GMSTileLayer is used to determine the number of tiles. While the zoom for camera is used to determine the number of points based on the formula 256 * 2N.

I could be wrong but I think both the zoom levels would not be matched up.

Not so related: Google just released iOS Maps SDK V1.8.1 that solved an issue related to GMSTileLayer and also fixed a crash.

这篇关于GMSTileURLConstructor返回缩放的奇怪数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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