2014-12-03 98 views
1

我使用Google Maps API v3在地圖上顯示一些位置。基本上它的工作原理如下:有一個管理區域可以向數據庫添加新的位置。當添加新位置時,我使用Geocoder服務檢查LatLng值並將地址+ LatLng保存到數據庫。之後,我只需通過LatLng值顯示地圖+標記。這工作得很好。如何使用Google Maps API v3突出顯示地址?

var myLatlng = new google.maps.LatLng(52.494406, 13.429538); 

var mapOptions = { 
    zoom: 15, 
    center: myLatlng 
} 

var map = new google.maps.Map(document.getElementById('gmap'), mapOptions); 

var marker = new google.maps.Marker({ 
    position: myLatlng, 
    map: map 
}); 

我在這裏錯過的是突出顯示的地址,如下面的截圖所示。

Google Maps Address Highlighting

+2

如果你投下來的問題,請解釋原因。 – Aley 2014-12-03 14:06:03

回答

1

你可以使用MarkerWithLabelDocumentation here.

function initialize() { 
 

 
    var myLatlng = new google.maps.LatLng(-34.668520, -58.543857); 
 
    var mapOptions = { 
 
    zoom: 14, 
 
    center: myLatlng 
 
    } 
 
    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 
 

 
    var marker_labeled = new MarkerWithLabel({ 
 
    position: myLatlng, 
 
    draggable: true, 
 
    raiseOnDrag: true, 
 
    map: map, 
 
    labelContent: "OneWay's Home", 
 
    labelAnchor: new google.maps.Point(-20, 10), 
 
    labelClass: "markerLabel", // the CSS class for the label 
 
    labelStyle: { 
 
     opacity: 0.75 
 
    } 
 
    }); 
 

 
} 
 

 
google.maps.event.addDomListener(window, 'load', initialize);
html, 
 
body, 
 
#map-canvas { 
 
    height: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
} 
 

 
.markerLabel { 
 
    color: black; 
 
    font-weight: bold; 
 
    text-shadow: 0px 0px 5px rgba(255, 0, 0, 1); 
 
}
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> 
 
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.9/src/markerwithlabel.js"></script> 
 

 
<div id="map-canvas"></div>

+0

@Aley任何反饋? – 2014-12-03 22:24:47

+0

這實際上是一個很好的解決方案,但我想知道是否有一個更簡單的方法(無需額外的庫)來顯示地址標籤,就像它在maps.google.com上的原生地址一樣。如果沒有「選項」解決方案,我會稍等一會並接受您的答案。非常感謝你的幫助! – Aley 2014-12-04 12:11:25

相關問題