0

目前我必须按地图右上角的a来显示我当前的位置(就是图中的小人),有没有办法在地图加载时自动显示你的位置?我还附上了代码和一张图片来解释。谢谢,对于我缺乏知识,我提前道歉。 在此处输入图像描述

<html>
  <head>
    <script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=Kmjtd%7Cluua2qu7n9%2C7a%3Do5-lzbgq"></script>

    <script type="text/javascript">

      /*An example of using the MQA.EventUtil to hook into the window load event and execute defined function
      passed in as the last parameter. You could alternatively create a plain function here and have it
      executed whenever you like (e.g. <body onload="yourfunction">).*/

      MQA.EventUtil.observe(window, 'load', function() {

        /*Create an object for options*/
        var options={
          elt:document.getElementById('map'),        /*ID of element on the page where you want the map added*/
          zoom:13,                                   /*initial zoom level of map*/
          latLng:{lat:40.735383, lng:-73.984655},    /*center of map in latitude/longitude*/
          mtype:'osm'                                /*map type (osm)*/
        };

        /*Construct an instance of MQA.TileMap with the options object*/
        window.map = new MQA.TileMap(options);

        MQA.withModule('geolocationcontrol', function() {
          map.addControl(
            new MQA.GeolocationControl()
          );
        });
      });

    </script>
  </head>

  <body>
    <div id='map' style='width:750px; height:280px;'></div>
  </body>
</html>
4

1 回答 1

0

根据文档,您可以在创建地理定位控件后尝试调用activate它。
如果这不会导致重新居中/缩放,那么您可能需要为 onLocate 回调注册一个处理程序(也在控件中)。当您的回调被调用时,您可以手动重新居中/缩放地图。请记住,地理定位可能非常不准确,自动进行可能会惹恼这种情况的用户。

于 2014-01-13T18:21:54.173 回答