簡體   English   中英

如何指出Google地圖中的特定位置?

[英]How can I point out a specific location in Google Maps?

如何指出Google地圖中的特定位置? 我曾嘗試看過這些問題,但沒有發現任何可以“幫助”我的東西。

的JavaScript

<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
  function initialize() {
    var mapCanvas = document.getElementById('map');
    var mapOptions = {
      center: new google.maps.LatLng(58.393584, 15.566656),
      zoom: 17,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(mapCanvas, mapOptions)
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

的CSS

#map {       
width: 500px;
height: 400px;
float: left;
margin: 10px;
margin-top: 15px;
}

(忽略marginfloat ),它確實會放大到該位置,但是如何添加指向它的指針? 指針的圖像會做嗎? 可能是一個新手問題,但是如果可以幫助我,謝謝。

您缺少Marker對象。
對於Label,您可以使用maplabel.js

 function initialize() { var mapCanvas = document.getElementById('map'); var mapOptions = { center: new google.maps.LatLng(58.393584, 15.566656), zoom: 17, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(mapCanvas, mapOptions); // MARKER: var marker = new google.maps.Marker({ position: mapOptions.center, label: "G", map: map }); // LABEL: var mapLabel = new MapLabel({ text: "Go here!", position: mapOptions.center, map: map, fontSize: 22, align: 'center' }); } google.maps.event.addDomListener(window, 'load', initialize); 
 #map { width: 500px; height: 400px; float: left; margin: 10px; margin-top: 15px; } 
 <script src="https://maps.googleapis.com/maps/api/js"></script> <script src="https://google-maps-utility-library-v3.googlecode.com/svn/trunk/maplabel/src/maplabel.js"></script> <div id="map"></div> 

而不是像這樣使用google maps API,我個人將Polymer用於google-map等google元素。

Polymer就是關於Web組件的所有元素,它非常簡單,干凈且易於使用。

google maps API如何與Polymer元素一起使用的示例

<google-map latitude="37.77493" longitude="-122.41942" fit-to-markers>
  <google-map-marker latitude="37.779" longitude="-122.3892"
      draggable="true" title="This is a title"></google-map-marker>
  <google-map-marker latitude="37.777" longitude="-122.38911"></google-map-marker>
</google-map>

它非常簡單和靈活。

如果您有興趣,請訪問以下文檔鏈接:

https://elements.polymer-project.org/elements/google-map

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM