【问题标题】:Using Tiled Google Map With OpenLayers 3在 OpenLayers 3 中使用平铺的 Google 地图
【发布时间】:2015-11-29 14:03:52
【问题描述】:

如何在 OpenLayers 3 中使用谷歌地图?
我想从 OpenLayers 2 迁移到 3。 这是一个例子: google map integration with OpenLayers example
但是使用这种方法需要更改旧的 HTML 代码(需要两个元素,示例中提到的 'gmap' 和 'olmap')。
ol3 官方不支持谷歌地图,但我的问题是:
“如何在我的项目中像 MapServer 一样使用 Google Maps Tile Service,而无需在脚本标签中添加 google API reference(用于优化目的)?”

这是我在 OpenLayers 2 中正常工作的旧代码:

var map = new OpenLayers.Map("map_canvas", {
    controls: [
        new OpenLayers.Control.PanZoomBar(),
        new OpenLayers.Control.ScaleLine(),
        new OpenLayers.Control.MousePosition(),
        new OpenLayers.Control.OverviewMap()
    ],
    units: "m",
    numZoomLevels: 21
});
var gmap = new OpenLayers.Layer.Google(
    { type: google.maps.MapTypeId.ROADMAP, numZoomLevels: 21}
);
map.addLayers([gmap]);

和html代码:

<div id="map_canvas">
</div>

感谢任何帮助。

【问题讨论】:

  • 您不能在没有 API 的情况下使用 google 的磁贴,这违反了使用条款(因此很难执行/维护)
  • 那么,如何在不更改旧 html 代码的情况下在 OpenLayers 3 中使用谷歌地图?
  • 你尝试了什么?向我们展示您的代码。
  • @steenhulthin:谢谢,问题已更新。
  • 有一个外部库见:github.com/mapgears/ol3-google-maps

标签: javascript google-maps gis openlayers-3 mapserver


【解决方案1】:

我找到了解决办法:

JsFiddle

var map = new ol.Map({
  target: 'map',
  layers: [
    new ol.layer.Tile({
        source: new ol.source.OSM({
            url: 'http://mt{0-3}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
            attributions: [
                new ol.Attribution({ html: '© Google' }),
                new ol.Attribution({ html: '<a href="https://developers.google.com/maps/terms">Terms of Use.</a>' })
            ]
        })
    })
  ],
  view: new ol.View({
    center: ol.proj.transform(
        [-110, 45], 'EPSG:4326', 'EPSG:3857'),
    zoom: 3
  })
});
html, body, #map {
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%;
}
<link href="http://openlayers.org/en/master/css/ol.css" rel="stylesheet"/>
<script src="http://openlayers.org/en/master/build/ol.js"></script>
<div id="map"></div>

但我不确定此代码是否违反 Google 使用条款。

【讨论】:

  • 太棒了。你是怎么想出来的?
  • 我担心作为一个未记录的功能,他们可能会在未来拉扯地毯。在使用条款方面 - 我试图通读指南。我不是律师,但如果使用卫星图像,情况会有所不同,因为还需要添加对第 3 方的归属。根据他们的指南,您需要写“Powered by Google”或“Map data ©2015 Google”。请参阅 herehere。如果你有 API 许可证,它可能会有所不同。
  • 以这种方式使用 Google 磁贴是非法的。请参阅使用条款 (developers.google.com/maps/terms#section_10_1) 第 10.1a 节:“例如,您不得通过 Maps API 以外的界面或渠道(包括未记录的 Google 界面)访问地图图块或图像。”
  • @ahocevar:谢谢,但我不确定。正如“Danny C”所说,也许你可以在地图底部写一个文字来覆盖谷歌的使用条款。
  • 我意识到这是一篇较旧的帖子,但使用来自 OpenLayers 的 Google 磁贴是否仍然违反 Google 的 TOS?我点击了 ahocevar 上面提到的链接,但在 10.1 节的任何地方都找不到引用的文本。有谁知道您现在是否可以合法地这样做?
猜你喜欢
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多