我如何应用地理位置坐标从谷歌地图得到方向到一个特定的地方

How can i apply geolocation coordinates to get directions to a specific place from googlemaps?

本文关键字:方向 一个 谷歌地图 何应用 应用 地理位置 坐标      更新时间:2023-09-26

大家复活节快乐!

我正在尝试学习更多关于html5中的地理位置。我使用的是来自estebanav @ github的geoPosition.js。(遵循phpacademy的教程)

我到目前为止能够获得一个潜在用户的坐标(我正在提醒)使用这个代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
        <title>Test</title>
    </head>
    <body>
        <a href="#" id="get_location">Get location</a>
        <div id="map">
            <iframe id="google_map" width="450" height="500" 
                    framehold="0" scrolling="no" marginheight="0" marginwidth="0"
                    src="https://maps.google.se?output=embed"></iframe>
        </div>

        <script src="js/geoPosition.js"></script>
        <script>
        document.getElementById('get_location').onclick = function() {
            var success = function(pos) {
                var lat     = pos.coords.latitude,
                    long    = pos.coords.longitude,
                    coords  = lat + ',' + long;
                alert(coords);
            }
            var error = function() {
                alert('Geolocation not supported...');
            }
            if (geoPosition.init()) {
                geoPosition.getCurrentPosition(success, error);
            }
            return false;
        }
        </script>
    </body>
</html>

我真的很想现在学习如何使用这些坐标并将它们作为方向的起点。

例如:假设我生成的坐标,变量坐标,是位置(58.408221,15.564322),我有一个目标点,例如一个变量goal_point,它的坐标是(58.418954,15.600543),我现在如何使用这些坐标在我的地图上显示方向,就像谷歌地图一样?

任何帮助或有价值的链接关于这将是感激!/比尔

首先,您需要开始使用Google Maps api而不是iframe。

从这里开始学习如何使用Maps Api v3显示基本地图。

在实现了一个基本的地图之后,你可以使用Google Directions Service来显示两点之间的路线。文档在这里