2010-08-09 121 views
5

上添加字母來標記我我想信添加到我的標記,然後有多個標記(14是準確的)字母。到目前爲止,我沒有成功。我是一個具有代碼和谷歌API的完全新手。谷歌地圖API:我的谷歌地圖

你能告訴什麼碼L需要添加,在哪裏?

下面是我的代碼:

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=.... 
    type="text/javascript"></script> 
<script type="text/javascript"> 
//<![CDATA[ 
function load() { 
    if (GBrowserIsCompatible()) { 

    var map = new GMap2(document.getElementById("map")); 
    map.addControl(new GMapTypeControl()); 
    map.addControl(new GLargeMapControl()); 
    map.addControl(new GOverviewMapControl()); 
    map.addControl(new GScaleControl()); 


    var bounds = map.getBounds(); 
    var southWest = bounds.getSouthWest(); 
    var northEast = bounds.getNorthEast(); 
    var lngSpan = northEast.lng() - southWest.lng(); 
    var latSpan = northEast.lat() - southWest.lat(); 
    for (var i = 0; i < 10; i++) { 
    var point = new GLatLng(southWest.lat() + latSpan * Math.random(), 
     southWest.lng() + lngSpan * Math.random()); 
    map.addOverlay(new GMarker(point)); 

    var point = new GLatLng(lat,ling); 
    map.setCenter(point, 10); 
    var marker = new GMarker(point); 
    map.addOverlay(marker); 

}

GEvent.addListener(map, "moveend", function() { 
    var center = map.getCenter(); 
    document.getElementById("message").innerHTML = center.toString(); 
    }); 



    map.setCenter(new GLatLng(lat,ling), 7); 

    } 
} 
//]]> 
</script> 
<style type="text/css"> 

展館位置

感謝

+0

>>我想信添加到我的標記 - 你是不是想改變圖標本身?我不確定你想要做什麼。 – praethorian 2010-08-11 16:04:40

回答

9
+0

我不確定問題出在哪裏。使用Charts API有什麼問題?提供字母標記超出了Maps API本身的範圍。如果你想要綠色的,請嘗試http://maps.gstatic.com/intl/en_us/mapfiles/marker_greenA.png(用所需的字母替換A) – 2010-10-28 06:14:04

12

下面是添加代碼標記與字母。

markerB = new google.maps.Marker({ 
     position: pointB, 
     title: "point B", 
     label: "B", 
     map: map 
    }) 

Google Maps JavaScript API V3 Reference:運行所有標記的循環,定義標記對象這樣當指數是每個標記位置

var letter = String.fromCharCode("A".charCodeAt(0) + index), 
marker = new google.maps.Marker({ 
    map: this.map, 
    position: latLongObj, 
    icon: "http://maps.google.com/mapfiles/marker" + letter + ".png", 
    animation: google.maps.Animation.DROP 
}); 

Here is the list of map marker icons

2

使用label選項

類型:string | MarkerLabel添加一個標籤來標記。標籤 可以是字符串或MarkerLabel對象。只顯示字符串的第一個字符 。

function initMap() { 
 
    var pointA = new google.maps.LatLng(51.2750, 1.0870), 
 
    pointC = new google.maps.LatLng(50.8429, -0.1313), 
 
    pointB = new google.maps.LatLng(51.5379, 0.7138), 
 
    myOptions = { 
 
     zoom: 7, 
 
     center: pointA, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }, 
 
    map = new google.maps.Map(document.getElementById('map-canvas'), myOptions), 
 
    markerA = new google.maps.Marker({ 
 
     position: pointA, 
 
     title: "point A", 
 
     label: "AAA", 
 
     map: map 
 
    }), 
 
    markerB = new google.maps.Marker({ 
 
     position: pointB, 
 
     title: "point B", 
 
     label: "B", 
 
     map: map 
 
    }), 
 
    markerC = new google.maps.Marker({ 
 
     position: pointC, 
 
     title: "point C", 
 
     label: "C", 
 
     map: map 
 
    }); 
 
} 
 

 
initMap();
html, 
 
body { 
 
    height: 100%; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
#map-canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
}
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
 

 

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

而這裏的同demo on Jsfiddle