2017-08-01 36 views

回答

-1

將您的緯度/經度設置爲郵局(或其他城市指示器)的位置。 然後,使用縮放屬性來修復您想要包含的級別。

參見:https://developers.google.com/maps/documentation/javascript/examples/marker-simple

這裏是代碼形式例如:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <title>Simple markers</title> 
    <style> 
     /* Always set the map height explicitly to define the size of the div 
     * element that contains the map. */ 
     #map { 
     height: 100%; 
     } 
     /* Optional: Makes the sample page fill the window. */ 
     html, body { 
     height: 100%; 
     margin: 0; 
     padding: 0; 
     } 
    </style> 
    </head> 
    <body> 
    <div id="map"></div> 
    <script> 

     function initMap() { 
     var myLatLng = {lat: -25.363, lng: 131.044}; 

     var map = new google.maps.Map(document.getElementById('map'), { 
      zoom: 4, 
      center: myLatLng 
     }); 

     var marker = new google.maps.Marker({ 
      position: myLatLng, 
      map: map, 
      title: 'Hello World!' 
     }); 
     } 
    </script> 
    <script async defer 
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"> 
    </script> 
    </body> 
</html> 

嘗試該腳本在map.zoom = 16應接近城市視圖。倫敦我想。

你也可以設置地圖界限,但這是一個很難。您需要找到您的位置,然後在該區域周圍繪製幾何圖形,定義點,然後將所有點縮放到視圖中。 所有這一切都是可能的,但你沒有給我看代碼,所以我沒有回頭。

希望你找到一些有用的東西,

+0

如果你打算投票,解釋什麼是錯的。我會修復我的答案或刪除它。 – JRodd

+0

我沒有給出代碼,因爲這個問題很模糊,他們給了我什麼都不能修復,而是一個想法。現在,我已將代碼放置在可能會更改的頁面上,因爲在這種情況下,鏈接比代碼​​更好。由於Google地圖將維護該開發人員鏈接,因此我不會保留該帖子。我試圖幫助。 – JRodd

+0

謝謝你的想法。不過,這個問題很模糊。 –

相關問題