【问题标题】:Google maps URL: is it possible to combine query and map options?谷歌地图网址:是否可以结合查询和地图选项?
【发布时间】:2018-11-09 12:05:40
【问题描述】:

我想搜索坐标、显示标记、切换到卫星(并且可以选择倾斜视图,北对齐 45 度)。示例:https://goo.gl/maps/H1SFmN9un582

https://developers.google.com/maps/documentation/urls/guide 列出了可用的 URL 参数,但它们被分成多个部分(搜索、路线、地图、街景)。当我尝试在搜索中使用地图参数时,反之亦然,它们会被忽略。我能做到的最好的办法是将地图居中于坐标,但随后图钉丢失了:

https://www.google.com/maps/@?api=1&map_action=map&center=48.792260,9.232073&zoom=18&basemap=satellite

【问题讨论】:

    标签: api google-maps url


    【解决方案1】:

    从下面的脚本中你可以得到 lat 和 log 然后很容易找到点

    <!doctype html>
    <html lang="en">
    <head>
        <title>Using the scripts in web pages</title>
        <meta charset="utf-8">
        <script defer src="//cdn.rawgit.com/chrisveness/geodesy/v1.1.2/latlon-spherical.js"></script>
        <script defer src="//cdn.rawgit.com/chrisveness/geodesy/v1.1.2/dms.js"></script>
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                document.querySelector('#calc-dist').onclick = function() {
                    const lat1 = document.querySelector('#lat1').value;
                    const lon1 = document.querySelector('#lon1').value;
                    const lat2 = document.querySelector('#lat2').value;
                    const lon2 = document.querySelector('#lon2').value;
                    const p1 = new LatLon(Dms.parseDMS(lat1), Dms.parseDMS(lon1));
                    const p2 = new LatLon(Dms.parseDMS(lat2), Dms.parseDMS(lon2));
                    const dist = parseFloat(p1.distanceTo(p2).toPrecision(4));
                    document.querySelector('#result-distance').textContent = dist;
                }
            });
        </script>
    </head>
    <body>
        <form>
            Lat 1: <input type="text" name="lat1" id="lat1">
            Lon 1: <input type="text" name="lon1" id="lon1">
            Lat 2: <input type="text" name="lat2" id="lat2">
            Lon 2: <input type="text" name="lon2" id="lon2">
            <button type="button" id="calc-dist">Calculate distance</button>
            <output id="result-distance"></output> metres
        </form>
    </body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-18
      相关资源
      最近更新 更多