• <tfoot id='QxHFM'></tfoot>
    <legend id='QxHFM'><style id='QxHFM'><dir id='QxHFM'><q id='QxHFM'></q></dir></style></legend>
      • <bdo id='QxHFM'></bdo><ul id='QxHFM'></ul>
      <i id='QxHFM'><tr id='QxHFM'><dt id='QxHFM'><q id='QxHFM'><span id='QxHFM'><b id='QxHFM'><form id='QxHFM'><ins id='QxHFM'></ins><ul id='QxHFM'></ul><sub id='QxHFM'></sub></form><legend id='QxHFM'></legend><bdo id='QxHFM'><pre id='QxHFM'><center id='QxHFM'></center></pre></bdo></b><th id='QxHFM'></th></span></q></dt></tr></i><div id='QxHFM'><tfoot id='QxHFM'></tfoot><dl id='QxHFM'><fieldset id='QxHFM'></fieldset></dl></div>

        <small id='QxHFM'></small><noframes id='QxHFM'>

        使用谷歌地图、PHP 和 MySQL 从 A 点到 B 点的距离

        时间:2023-09-25

          <i id='yFF3o'><tr id='yFF3o'><dt id='yFF3o'><q id='yFF3o'><span id='yFF3o'><b id='yFF3o'><form id='yFF3o'><ins id='yFF3o'></ins><ul id='yFF3o'></ul><sub id='yFF3o'></sub></form><legend id='yFF3o'></legend><bdo id='yFF3o'><pre id='yFF3o'><center id='yFF3o'></center></pre></bdo></b><th id='yFF3o'></th></span></q></dt></tr></i><div id='yFF3o'><tfoot id='yFF3o'></tfoot><dl id='yFF3o'><fieldset id='yFF3o'></fieldset></dl></div>

            <small id='yFF3o'></small><noframes id='yFF3o'>

            <legend id='yFF3o'><style id='yFF3o'><dir id='yFF3o'><q id='yFF3o'></q></dir></style></legend>
          • <tfoot id='yFF3o'></tfoot>

                  <bdo id='yFF3o'></bdo><ul id='yFF3o'></ul>
                    <tbody id='yFF3o'></tbody>
                  本文介绍了使用谷歌地图、PHP 和 MySQL 从 A 点到 B 点的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  谁能帮忙.我只需要一个简单的脚本.我有一个表格张贴到另一个页面.两个表单域是:

                  Can anyone please help. I just need a simple script. I have a form posted to another page. two formfields are:

                  fromaddress 和 toaddress

                  fromaddress and toaddress

                  我唯一需要的是一个脚本,它可以显示以公里为单位的距离以及使用谷歌地图所需的时间.我找到了几十个脚本,但我无法让它工作.地图已经有了这个代码,看起来很完美.

                  The only thing I need is a script that shows me the distance in km and the time it takes using google maps. I have found dozens of scripts but I cannot get it working. The map is already there with this code which seems to work perfect.

                  <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=AIzaSyDdDwV6_l5n2bS3gM6NBCla3RFLtIFc_HE&sensor=false"></script><script type="text/javascript">
                      var directionDisplay;
                      var directionsService = new google.maps.DirectionsService();
                      var map;
                  
                      function initialize() {
                          directionsDisplay = new google.maps.DirectionsRenderer();
                          var myOptions = {
                              zoom: 8,
                              mapTypeId: google.maps.MapTypeId.ROADMAP,
                          }
                          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                          directionsDisplay.setMap(map);
                  
                          var start = "<? echo $_POST[fromaddress]; ?>";
                          var end = "<? echo $_POST[toaddress]; ?>";
                          var request = {
                              origin:start, 
                              destination:end,
                              travelMode: google.maps.DirectionsTravelMode.DRIVING
                          };
                          directionsService.route(request, function(response, status) {
                              if (status == google.maps.DirectionsStatus.OK) {
                                  directionsDisplay.setDirections(response);
                              }
                          });
                  
                      }
                  
                      $(document).ready(function(){
                          initialize();
                      });        
                  </script>
                  

                  但是我如何显示距离和时间.最好的选择是将它放入一个 php 值中,例如:

                  But how do i display the distance and the time. Best option is to get it in a php value like:

                  $distance = some-code;
                  $time = some-code-too;
                  

                  非常感谢您的帮助.

                  推荐答案

                  您需要为此使用不同的 API.首先,不要使用 JS 而是使用 PHP,这是应该对你有用的代码片段;)

                  You need to use different API for that. First of all, don't use JS but PHP, here's the code snippet that should work for you ;)

                  $from = "Więckowskiego 72, Łódź";
                  $to = "Gazowa 1, Łódź";
                  
                  $from = urlencode($from);
                  $to = urlencode($to);
                  
                  $data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");
                  $data = json_decode($data);
                  
                  $time = 0;
                  $distance = 0;
                  
                  foreach($data->rows[0]->elements as $road) {
                      $time += $road->duration->value;
                      $distance += $road->distance->value;
                  }
                  
                  echo "To: ".$data->destination_addresses[0];
                  echo "<br/>";
                  echo "From: ".$data->origin_addresses[0];
                  echo "<br/>";
                  echo "Time: ".$time." seconds";
                  echo "<br/>";
                  echo "Distance: ".$distance." meters";
                  

                  输出:

                  To: Gazowa 1, 91-076 Łódź, Poland
                  From: Więckowskiego 72, Łódź, Poland
                  Time: 206 seconds
                  Distance: 1488 meters
                  

                  这篇关于使用谷歌地图、PHP 和 MySQL 从 A 点到 B 点的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在mysql查询中找到所选对角线区域之间的准确 下一篇:在谷歌地图上绘制区域

                  相关文章

                  最新文章

                • <tfoot id='z4cwi'></tfoot>
                  <i id='z4cwi'><tr id='z4cwi'><dt id='z4cwi'><q id='z4cwi'><span id='z4cwi'><b id='z4cwi'><form id='z4cwi'><ins id='z4cwi'></ins><ul id='z4cwi'></ul><sub id='z4cwi'></sub></form><legend id='z4cwi'></legend><bdo id='z4cwi'><pre id='z4cwi'><center id='z4cwi'></center></pre></bdo></b><th id='z4cwi'></th></span></q></dt></tr></i><div id='z4cwi'><tfoot id='z4cwi'></tfoot><dl id='z4cwi'><fieldset id='z4cwi'></fieldset></dl></div>

                  1. <legend id='z4cwi'><style id='z4cwi'><dir id='z4cwi'><q id='z4cwi'></q></dir></style></legend>

                      <bdo id='z4cwi'></bdo><ul id='z4cwi'></ul>

                      <small id='z4cwi'></small><noframes id='z4cwi'>