将 Bing 地图图块集成到 Google 地图 API 中

发布于 2024-09-07 05:16:39 字数 475 浏览 10 评论 0 原文

我目前设法将 OpenStreetMap 集成到 Google Maps API 中,如 此示例。我想知道是否也可以将 Bing Maps tiles 集成到 Google Maps API 中。是否可以?我找不到任何相关信息。

注意:我确实了解 mapstraction,但目前我想坚持使用 Google Maps API。

提前致谢。

I currently managed to integrate OpenStreetMap into Google Maps API as it is described in this example. I wonder if I can also integrate Bing Maps tiles into Google Maps API. Is it possible? I could not find anything about that.

Note: I do know about mapstraction but for now, I would like to stick to Google Maps API.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ヤ经典坏疍 2024-09-14 05:16:39

根据您引用的 OpenStreetMap 示例,我想说这是可能的,但可能是一个相当大的挑战。我强烈建议不要这样做,因为 OSM 示例使用 Google API 的版本 2,并且现已正式弃用。

但如果您想尝试一下,我会调整 OSM 示例以指向 Bing 图块,并确保 tileUrlTemplate 属性与 Bing 存储图块的格式匹配。不幸的是,Bing 使用四叉树格式,而 Google 使用基于坐标的格式,用于存储图块并通过网址访问它们。如果您要使该示例正常工作,那么了解这些差异非常重要,因此请务必深入研究上面的文档链接。此外,MapTiler 还可以对不同图块格式进行出色的可视化在那里。我发现这是无价的。

就我个人而言,我会使用 OpenLayers。由于 Bing 和 Google 都使用球形墨卡托,因此向单个地图添加多个图块源是一项微不足道的练习。 这里是一个示例。

Based on the OpenStreetMap example that you cited, I would say that it's possible but it could be quite a challenge. I would strongly advise against it since the OSM example uses version 2 of the Google API and it now officially deprecated.

But if you want to give it a try I would adapt the OSM example to point to the Bing tiles and make sure that the tileUrlTemplate property matches Bing's format for storing tiles. Unfortunately, Bing uses a quad tree format while Google uses a coordinate based format for storing tiles and accessing them via a URL. It will be important to understand the differences if you're going to make the example work so be sure to dig into the documentation links above. Also, MapTiler has a fantastic visualization of the different tile formats out there. I've found this invaluable.

Personally, I would use OpenLayers. Since Bing and Google both use spherical mercator, adding multiple tile sources to a single map is a trivial exercise. Here is an example.

碍人泪离人颜 2024-09-14 05:16:39
function TileToQuadKey ( x, y, zoom){ 
  var quad = "";
  for (var i = zoom; i > 0; i--) {
    var mask = 1 << (i - 1); 
    var cell = 0; 
    if ((x & mask) != 0) cell++; 
    if ((y & mask) != 0) cell += 2; 
    quad += cell; 
  }
  return quad; 
}

var bingMapType = new google.maps.ImageMapType({
  name: "Bing",
  getTileUrl: function(coord, zoom) {
    // this returns aerial photography
    return "http://ecn.t1.tiles.virtualearth.net/tiles/a" +
      TileToQuadKey(coord.x, coord.y,  zoom) + ".jpeg?g=1173&n=z";
      // i dont know what g=1173 means
  },
  tileSize: new google.maps.Size(256, 256),
  maxZoom: 21
});
function TileToQuadKey ( x, y, zoom){ 
  var quad = "";
  for (var i = zoom; i > 0; i--) {
    var mask = 1 << (i - 1); 
    var cell = 0; 
    if ((x & mask) != 0) cell++; 
    if ((y & mask) != 0) cell += 2; 
    quad += cell; 
  }
  return quad; 
}

var bingMapType = new google.maps.ImageMapType({
  name: "Bing",
  getTileUrl: function(coord, zoom) {
    // this returns aerial photography
    return "http://ecn.t1.tiles.virtualearth.net/tiles/a" +
      TileToQuadKey(coord.x, coord.y,  zoom) + ".jpeg?g=1173&n=z";
      // i dont know what g=1173 means
  },
  tileSize: new google.maps.Size(256, 256),
  maxZoom: 21
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文