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

      <legend id='VPqOl'><style id='VPqOl'><dir id='VPqOl'><q id='VPqOl'></q></dir></style></legend>
    1. <small id='VPqOl'></small><noframes id='VPqOl'>

      • <bdo id='VPqOl'></bdo><ul id='VPqOl'></ul>

        Google maps API - 客户当前位置的中心地图

        时间:2023-09-06
        • <i id='tHkAq'><tr id='tHkAq'><dt id='tHkAq'><q id='tHkAq'><span id='tHkAq'><b id='tHkAq'><form id='tHkAq'><ins id='tHkAq'></ins><ul id='tHkAq'></ul><sub id='tHkAq'></sub></form><legend id='tHkAq'></legend><bdo id='tHkAq'><pre id='tHkAq'><center id='tHkAq'></center></pre></bdo></b><th id='tHkAq'></th></span></q></dt></tr></i><div id='tHkAq'><tfoot id='tHkAq'></tfoot><dl id='tHkAq'><fieldset id='tHkAq'></fieldset></dl></div>

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

        • <tfoot id='tHkAq'></tfoot>
            <bdo id='tHkAq'></bdo><ul id='tHkAq'></ul>

              <tbody id='tHkAq'></tbody>

                <legend id='tHkAq'><style id='tHkAq'><dir id='tHkAq'><q id='tHkAq'></q></dir></style></legend>

                  本文介绍了Google maps API - 客户当前位置的中心地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经查看了这个问题被问到的各种其他时间,但我不能完全指出我哪里出错了,这是我的代码:

                  I've looked at the various other times this question has been asked but I can't quite put a finger on where I'm going wrong, here's my code:

                  <html>
                  <head>
                      <title> Map </title>
                      <style>
                          html, body, #map-canvas {
                          margin: 0;
                          padding: 0;
                          height: 500px;
                          width: 800px;}
                      </style>
                      <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
                      <script>
                          var map;
                          function initialize()
                          {
                              var myLatlng1 = new google.maps.LatLng(53.65914, 0.072050);
                  
                              var mapOptions = 
                              {
                                  zoom: 10,
                                  center: myLatlng1,
                                  mapTypeId: google.maps.MapTypeId.ROADMAP
                              };
                              var map = new google.maps.Map(document.getElementById('map-canvas'),
                              mapOptions);
                  
                  
                              <?php
                                  $sql = mysql_query("SELECT * FROM data ORDER BY ID DESC");
                                  while($row =mysql_fetch_array($sql))
                                  {
                                      $desc = $row['DESCRIPTION'];
                                      $location = $row['LOCATION'];
                                      $counter += 1; 
                                  ?>
                  
                              var marker = new google.maps.Marker({
                                  position: new google.maps.LatLng(<?php echo $location; ?>),
                                  map: map,
                                  title: '<?php echo $desc; ?>',
                                  icon: '/image/cam.png'
                              });
                  
                             navigator.geolocation.getCurrentPosition(showPosition);  
                          }
                  
                          var showPosition = function (position) 
                             {
                                 map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude), 16);
                  
                             }
                  
                          google.maps.event.addDomListener(window, 'load', initialize);
                  
                      </script>
                  </head>
                  

                  它最初将中心设置为myLatlng1,而底部将其设置为用户当前位置的代码没有做任何事情,有什么想法吗?

                  It originally sets the center to myLatlng1, and the code at the bottom to set it to the user's current location doesn't do anything, any ideas?

                  提前致谢.

                  推荐答案

                  尝试使用以下代码获取用户当前位置(GEOLOCATION):

                  Try using the below code to get the user's current location (GEOLOCATION):

                   if (navigator.geolocation) {
                       navigator.geolocation.getCurrentPosition(function (position) {
                           initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                           map.setCenter(initialLocation);
                       });
                   }
                  

                  为了展示一个例子,我删除了你的 php 代码.检查这个 JSFiddle

                  For showing an example, I've removed your php code. Check this JSFiddle

                  希望你能理解.

                  这篇关于Google maps API - 客户当前位置的中心地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:需要从谷歌地图API获取纬度和经度 下一篇:通过 html5 和 javascript 获取用户地理位置

                  相关文章

                  最新文章

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

                      <tfoot id='v6geI'></tfoot>

                      • <bdo id='v6geI'></bdo><ul id='v6geI'></ul>

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

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