显示方向的每一步地理编码

发布于 2024-08-26 07:37:58 字数 362 浏览 10 评论 0原文

Google Maps API 可以构建从源到目的地的路线。在以下 Google 示例中,每个步骤都发布到 HTML 代码中: http://code.google.com/apis/maps/documentation/examples/directions-simple.html

我想获取此方向每个步骤的地理编码,并将它们存储在数组中。我相信这是可能的,但我不知道如何处理。

非常感谢您的回答。 问候

Google Maps API can build a Direction from a source to a destination. In the following Google's example, each step are published into the HTML code: http://code.google.com/apis/maps/documentation/examples/directions-simple.html

I would like to get the Geocoding of each step of this direction, and store them in a array. I believe it's possible, but I don't see how to process.

Many Thanks for any answer.
Regards

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

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

发布评论

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

评论(1

铁轨上的流浪者 2024-09-02 07:37:58

是的,您可以轻松地从 GDirections 获取各个步骤。

首先,您必须确保在调用 GDirections.load() 方法时传递 getSteps: true 选项。然后,您可以简单地迭代 GDirections.getRoute(i).getStep(j),如以下示例所示:

<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps Simple Directions Demo</title> 
   <script src="http://maps.google.com/maps?file=api&v=2&sensor=false" 
              type="text/javascript"></script>
</head> 
<body onunload="GUnload()">
   <div id="map" style="width: 550px; height: 400px"></div> 

   <script type="text/javascript"> 
      var map = new GMap2(document.getElementById("map"));
      var directions = new GDirections(map);

      directions.load('from: London, UK to: Glasgow, UK', { getSteps: true });

      GEvent.addListener(directions, "load", function() {
         if (directions.getNumRoutes() > 0) {
            for (var i = 0; i < directions.getRoute(0).getNumSteps(); i++) {
               directions.getRoute(0).getStep(i).getLatLng().lat();
               directions.getRoute(0).getStep(i).getLatLng().lng();
               directions.getRoute(0).getStep(i).getDescriptionHtml();
               directions.getRoute(0).getStep(i).getPolylineIndex();
               directions.getRoute(0).getStep(i).getDistance().meters;
               directions.getRoute(0).getStep(i).getDuration().seconds;
            }
         }
      });
   </script> 
</body> 
</html>

进一步阅读和参考:

Yes, you can get the individual steps from GDirections very easily.

First you have to make sure to pass the getSteps: true option when you call the GDirections.load() method. Then you can simply iterate through GDirections.getRoute(i).getStep(j), as in the following example:

<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps Simple Directions Demo</title> 
   <script src="http://maps.google.com/maps?file=api&v=2&sensor=false" 
              type="text/javascript"></script>
</head> 
<body onunload="GUnload()">
   <div id="map" style="width: 550px; height: 400px"></div> 

   <script type="text/javascript"> 
      var map = new GMap2(document.getElementById("map"));
      var directions = new GDirections(map);

      directions.load('from: London, UK to: Glasgow, UK', { getSteps: true });

      GEvent.addListener(directions, "load", function() {
         if (directions.getNumRoutes() > 0) {
            for (var i = 0; i < directions.getRoute(0).getNumSteps(); i++) {
               directions.getRoute(0).getStep(i).getLatLng().lat();
               directions.getRoute(0).getStep(i).getLatLng().lng();
               directions.getRoute(0).getStep(i).getDescriptionHtml();
               directions.getRoute(0).getStep(i).getPolylineIndex();
               directions.getRoute(0).getStep(i).getDistance().meters;
               directions.getRoute(0).getStep(i).getDuration().seconds;
            }
         }
      });
   </script> 
</body> 
</html>

Further reading and reference:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文