2014-01-12 33 views
0

目前我必須按下地圖右上角的地圖來顯示我的當前位置(它是圖片中的小人物),有沒有辦法在地圖加載時自動顯示您的位置?我附上了代碼以及一張照片來解釋。謝謝,我由於缺乏知識而提前道歉。 enter image description here我希望Mapquest OSM地理位置自動顯示您的當前位置,但它不是?

<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> 
+0

是否有任何形式的共性,它* *是否居中? –

+0

@andrewBarber它圍繞geolocater提供的位置。如果這是有道理的,如果不是,你的意思是什麼? – user2083920

+0

那麼你現在的代碼有什麼問題? – MaM

回答

0

基礎上documentation,你可以嘗試在地理位置調用控件activate創建後。
如果這不會導致重新居中/縮放,那麼您可能需要爲onLocate回調(也在控件中)註冊一個處理函數。當你的回調被呼叫時,你可以手動重新居中/縮放地圖。 請記住,地理位置可能非常不準確,自動執行此操作可能會令用戶感到困惑。

相關問題