【问题标题】:How to use Google Maps API in leaflet-cloudmade如何在 Leaflet-cloudmade 中使用 Google Maps API
【发布时间】:2012-06-19 14:38:46
【问题描述】:

有没有办法将谷歌地图与leaflet-cloudmade 集成? 我的意思是,我不想使用原始的 cloudmade 地图,但我想使用谷歌地图。我想展示阿拉斯加的地图(那里的道路不多)。如果我使用云地图,它只是白色的。

如果我想使用 cloudmade 地图,我会这样做:

var cloudmade = new L.TileLayer('http://{s}.tile.cloudmade.com/YOUR-API-KEY/997/256/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
    maxZoom: 18
});

我知道我应该更改 'http://{s}.tile.cloudmade.com/YOUR-API-KEY/997/256/{z}/{x}/{y}.png ' 部分。但是,如果我想使用谷歌地图(或任何其他地图),我应该在那里写什么?

这是leaflet-cloudmade的文档(他们没有说太多关于使用third-party map provider。他们说他们对我们应用程序中使用的地图提供者不可知论,所以我认为应该可以使用谷歌地图)。

【问题讨论】:

  • @dda :感谢您编辑我的问题。

标签: google-maps gis leaflet


【解决方案1】:

来自this:

这个plugin for Debian没有这个问题,但是不符合google (Oficial example)的服务条款。

或者试试这个代码:

var map = L.map( 'map' ).setView( [ 51.505, -0.09 ], 13 );

L.tileLayer( '//mt{s}.googleapis.com/vt?x={x}&y={y}&z={z}',
{
  maxZoom: 18,
  subdomains: [ 0, 1, 2, 3 ]
} ).addTo( map );

var marker = L.marker( [ 51.5, -0.09 ] ).addTo( map );

【讨论】:

    【解决方案2】:

    它实际上不是 Google 地图,但有很多不同的 LeafLet 地图提供程序,示例代码可在 http://leaflet-extras.github.io/leaflet-providers/preview/ 获得

    也许您可以在那里找到适合您特定问题的提供商。另外,您将避免 Andrew Leach 指出的问题。无论如何 - 并不是我希望你不知道,但我仍然不想忽略这一点 - 请注意,一些(但不是全部)地图提供者是商业提供者,因此你可能需要为服务付费或者可能会担心其他 TOS。

    【讨论】:

    • 感谢您的告知。
    【解决方案3】:

    official leaflet.js plugins page 引用 Plugins by Pavel Shramov 包。
    根据使用条款,提供的 Google.js 可让您使用 Google Maps API v3 访问 Google 地图图块。

    这里是一个简单的例子:你可以通过先添加来使用它

    <script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
    <script src="path/to/Google.js"></script>
    

    然后构建你的地图:

    var map = new L.Map('map', {center: new L.LatLng(43.6481, -79.4042), zoom: 13});
    var gmap_layer = new L.Google('ROADMAP');
    map.addLayer(gmap_layer);
    

    注意:this gist中也提到了一些分叉。

    【讨论】:

      【解决方案4】:

      有一个第三方插件可将 Google 地图集成到 Leaflet 中,以便能够将其添加为图层:http://psha.org.ru/b/leaflet-plugins.html。但是,它充当原始 Google Maps API v3 的代理,因此它不像简单的 Leaflet 平铺层那样流畅,不幸的是,由于使用条款的限制,您不能直接使用 Google Maps 平铺(就像在答案中一样)以上)。

      【讨论】:

        【解决方案5】:

        Google 不允许您在不使用他们自己的 API 获取它们的情况下使用他们的磁贴。见General Terms:

        不要滥用我们的服务。例如,不要...尝试使用我们提供的接口和指令以外的方法访问它们。

        当然,任何事情都是可能的,因此可以在没有 API 的情况下获取磁贴,但您的访问可能会在没有警告的情况下被阻止:

        如果您不遵守我们的条款或政策,或者我们正在调查可疑的不当行为,我们可能会暂停或停止向您提供我们的服务。

        也就是说,Leaflet API 与 Google API 看起来非常不同,因此转换为使用他们的 API 可能值得考虑。

        【讨论】:

        • 嗨,我以前不知道。感谢您提供此信息。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-15
        • 2018-12-22
        • 2021-03-26
        • 1970-01-01
        • 2014-10-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多