【发布时间】:2016-07-01 16:24:40
【问题描述】:
GMSTileURLConstructor GMSURLTileLayer 不显示图块
我正在尝试在谷歌地图上覆盖我自己的图块(tilestream)。 但它失败了。所以我决定尝试在谷歌地图上覆盖openstreet地图图块,因为tilestream的图块URL与openstreet地图的URL结构相同。两者都是http://xxx/z/x/y.png
使用 GMSTileURLConstructor GMSURLTileLayer,但显示图块失败
只有 google SDKdemo 示例可以正常工作。 网址是:
NSString *url = [NSString stringWithFormat:@"https://www.gstatic.com/io2010maps/tiles/9/L1_%tu_%tu_%tu.png",zoom, x, y];
如果我使用 openstreet URL,它无法在任何缩放级别显示自定义图块。
NSString *url = [NSString stringWithFormat:@"http://a.tile.openstreetmap.org/%tu/%tu/%tu.png", (unsigned long)zoom, (unsigned long)x, (unsigned long)y];
zIndex 设置为 99、100、1,仍然不显示图块。
我确认磁贴服务器工作正常,如果我直接在浏览器中使用 url,则可以正确接收磁贴图像。
还 google 示例平面图瓷砖、缩放、x、y 完全匹配 openstreet 地图缩放、x、y。
我不明白,为什么 google 示例磁贴 URL 可以正常工作,但 openstreet 地图 url 磁贴不显示。
这是我的代码:有人知道为什么吗?
- (void)viewDidLoad {
[super viewDidLoad];
//------------- google map ------------
// GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.6599244
// longitude:-117.915058135
// zoom:13];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:37.78318
longitude:-122.403874
zoom:18];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
//mapView_.myLocationEnabled = YES;
mapView_.mapType = kGMSTypeHybrid;
mapView_.buildingsEnabled = NO;
mapView_.indoorEnabled = NO;
self.view = mapView_;
// Create a new GMSTileLayer with the new floor choice.
GMSTileURLConstructor urls = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) {
//NSString *url = [NSString stringWithFormat:@"https://www.gstatic.com/io2010maps/tiles/9/L1_%tu_%tu_%tu.png",zoom, x, y];
//NSString *url = [NSString stringWithFormat:@"http://tile.openstreetmap.org/%tu/%tu/%tu.png", zoom, x, y];
NSString *url = [NSString stringWithFormat:@"http://a.tile.openstreetmap.org/%tu/%tu/%tu.png", (unsigned long)zoom, (unsigned long)x, (unsigned long)y];
NSLog(@"%@", url);
return [NSURL URLWithString:url];
};
layer = [GMSURLTileLayer tileLayerWithURLConstructor:urls];
layer.zIndex = 1;
layer.opacity= 0.5;
layer.map = mapView_;
【问题讨论】:
-
这是在安卓上吗?
-
不,它在 ios iphone 上
-
如何得到 x 和 y?
标签: ios google-maps