Ios GMSSyncTileLayer类---我如何在mapView中传递。。那么x和y到底是什么呢?

Ios GMSSyncTileLayer类---我如何在mapView中传递。。那么x和y到底是什么呢?,ios,swift,google-maps,gmsmapview,Ios,Swift,Google Maps,Gmsmapview,所以,我有一个在IBOutlet中声明的谷歌地图 @IBOutlet weak var mapView: GMSMapView! 我在idleAtCameraPosition函数中创建了我的GMSSyncTileLayer,如下所示 func mapView(mapView: GMSMapView!, idleAtCameraPosition position: GMSCameraPosition!) { var layer = TestTileLayer() layer.m

所以,我有一个在IBOutlet中声明的谷歌地图

@IBOutlet weak var mapView: GMSMapView!
我在idleAtCameraPosition函数中创建了我的GMSSyncTileLayer,如下所示

func mapView(mapView: GMSMapView!, idleAtCameraPosition position: GMSCameraPosition!) {

    var layer = TestTileLayer()
    layer.map = mapView
}
这是我的GMSSyncTileLayer

class TestTileLayer: GMSSyncTileLayer {
    //MainActivityX() is the name of the View Controller my GMSMapView is in ^
    let mainActivity = MainActivityX()

override func tileForX(x: UInt, y: UInt, zoom: UInt) -> UIImage! {

    NSLog("X: \(x)")
    NSLog("Y: \(y)")

    //This is nil :(
    NSLog("mapView: \(mainActivity.mapView)")

    var boost:Float = 1.00
    if let heatmap: UIImage = LFHeatMap.heatMapForMapView(mainActivity.mapView, boost:boost, locations:locations as[AnyObject]) {
        NSLog("heatmap")
        return heatmap
    }
    else {
        NSLog("kGMSTileLayerNoTile")
        return kGMSTileLayerNoTile
    }
}
这是我日志的摘录--

我的地图视图为零:(

有人能告诉我如何在地图视图中传递到这个GMSSyncTileLayer吗

或者告诉我如何使用x和y获得“mapView.projection”的等价物?因为这正是我从mapView中真正需要的

而且这些x和y值对我来说没有任何意义

虽然我在网上看了文件

^基于我得到的X和Y的值,这没有意义

2015-06-07 22:18:15.586 Hightide[7011:2387342] Y: 3133  ???
2015-06-07 22:18:15.587 Hightide[7011:2387344] X: 2339  ???
我仍然很难理解这些x和y值代表什么。当我一路放大时,它们会变为零,当我放大时,它们会越来越高。我知道这一点……但不理解这些值的含义

我真的在坐标(23393133)上吗?它在我地图的中心吗?我在看什么


谢谢!

您需要返回通常由支持x、y、缩放格式而不是lat、lng的api生成的平铺图像

我们使用天气api:

https://mycompany.madesmart.nl/fcst/get?zoom=4&x=3&y=5&type=precipitation_pressure&id=1566&token=MYTOKEN




@interface SNGMSSyncTileLayer : GMSSyncTileLayer

@end
实施

- (UIImage *)tileForX:(NSUInteger)x y:(NSUInteger)y zoom:(NSUInteger)zoom {
    NSLog(@"tileForX:(%lu) y:(%lu) zoom:(%lu)", x , y, zoom);
    UIImage * imageFrame = nil;

    //----------------------------------------------------------------------------------------
    //v2 - get tile image - problem - no caching will get same tile if you move away then back over it
    //----------------------------------------------------------------------------------------
    NSString *weatherType = @"cloudcoverage_pressure";
    weatherType = @"precipitation_pressure";

    NSString *urlString =
                    [NSString stringWithFormat:@"https://mycompany.madesmart.nl/fcst/get?zoom=%lu&x=%lu&y=%lu&type=%@&id=1566&token=MYTOKEN,
                                     (unsigned long)zoom,   /* %lu */
                                     (unsigned long)x,      /* %lu */
                                     (unsigned long)y,      /* %lu */
                                        weatherType
                     ];

    //----------------------------------------------------------------------------------------
    //V1 - DOWNLOAD SYNC
    //----------------------------------------------------------------------------------------
    //SYNCHRONOUS CALL IS OK AND REQUIRED
    // - the outer method is called async and result cached
    // - we need to return an UIImage in this method ANYWAY so have to wait for a result
    //----------------------------------------------------------------------------------------
    //OK but not cahced and redraws frame on itself
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];

    UIImage *sourceImage = [UIImage imageWithData: data];

    return imageFrame;

}
召唤

SNGMSSyncTileLayer *layer = [[SNGMSSyncTileLayer alloc] init];
// Display on the map at a specific zIndex
layer.zIndex = 100;
layer.opacity = 0.1;
layer.map = self.mapView;

当你得到(23393133)时,你处于什么样的缩放级别?我想这是说包含x,y对(23393133)的平铺是零。我处于缩放级别13。我如何使用这个x,y对和缩放来做有用的事情?我能用你认为的这些值得到mapView.projection的等价物吗?“我真的在坐标(23393133)上吗?”?它在我地图的中心吗?我在看什么?“数据是正确的。如果你尽可能靠近,你会看到类似的数据
SNGMSSyncTileLayer *layer = [[SNGMSSyncTileLayer alloc] init];
// Display on the map at a specific zIndex
layer.zIndex = 100;
layer.opacity = 0.1;
layer.map = self.mapView;