2014-05-16 52 views
5

我正在嘗試在Google Maps for iOS上使用GMSTileURLConstructor繪製自定義覆蓋圖。GMSTileURLConstructor返回縮放的奇怪數據

我使用下面的代碼讓我的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]; 
    }; 

當我登錄了網址,變焦和個zoomLevel我得到以下信息:

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

同時,我在相機更改時記錄相機變焦

- (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]; 
    } 
} 

哪些日誌

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

誰能解釋縮放級別值的差異,以及如何把它適當地匹配嗎?

+0

您正在使用的是哪個版本的Google地圖SDK? 1.8.0或1.7.2? – Ricky

+0

看起來像1.7.2。 – Jeremy1026

+0

你有沒有解決這個問題? – funkybro

回答

6

我做了一些研究之後,我相信谷歌的方式處理縮放級別GMSTileLayer不與縮放級別camera of mapView相同。

GMSTileLayer類參考

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

在縮放級別爲0的整個世界是由單個瓦片, 和座標x和y所覆蓋的正方形都是0該圖塊。在縮放級別1處, 世界被4個瓦片覆蓋,x和y爲0或1,依此類推。

對於的MapView相機

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

攝像機的縮放級別決定了地圖的比例尺。在 更大的縮放級別更多的細節可以在屏幕上看到,而在 更小的縮放級別可以在屏幕上看到更多的世界。在 縮放級別0,地圖的比例尺是這樣的,整個世界的寬度大約爲256點。

將縮放級別提高1倍,屏幕上的世界寬度加倍。因此,在縮放級別N處,世界的寬度大約是 256 * 2N,即在縮放級別2時,整個世界大約爲1024點寬度。請注意,縮放級別不需要是整數。地圖允許的縮放級別的範圍取決於多個因素,包括位置,地圖類型和屏幕大小。

變焦用於GMSTileLayerNSUIntegercamera變焦是浮子。GMSTileLayer的縮放用於確定瓦片數量。雖然根據公式256 * 2N確定點數

我可能是錯的,但我認爲這兩個縮放級別不匹配。

沒有這麼相關:Google剛剛發佈了iOS Maps SDK V1.8.1,它解決了與GMSTileLayer相關的問題,並修復了崩潰問題。

+0

....你知道Google現在是否已經解決了這個問題嗎? – user836026