簡體   English   中英

Android Marker的圖標

[英]Android Marker's icons

嗨,我有這個代碼,每次點擊添加標記按鈕時,都會在地圖上添加一個標記。 有關如何在地圖上添加標記時每次更改標記圖標的任何建議嗎? 非常感謝。

   function initialize() {
    var myLatlng = new google.maps.LatLng(40.779502, -73.967857);

    var myOptions = {
        zoom: 7,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    TestMarker();
      }
  google.maps.event.addDomListener(window, 'load', initialize);


  function addmarker(location) {
    marker = new google.maps.Marker({
        position: location,
        draggable:true,
        map: map
        for()
     });
    }

// Testing the addMarker function
function TestMarker() {
       CentralPark = new google.maps.LatLng(40.779502, -73.967857);
       addmarker(CentralPark);
  }

您可以使用Google的自定義地圖標記,例如他們提供的以下代碼段:

var marker = new google.maps.Marker({ position: myLatLng, map: map, icon: iconBase + 'schools_maps.png' });

為了在每次用戶添加標記時創建新圖標,您可以創建圖像位置數組,然后在每次用戶添加新圖像時遍歷數組。 以下是有關Google自定義標記的更多文檔:

https://developers.google.com/maps/tutorials/customizing/custom-markers

您還可以為特定要素定義特定標記,並將該要素作為參數傳遞。 Google還提供了一些此功能的示例代碼:

var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/'; var icons = { parking: { icon: iconBase + 'parking_lot_maps.png' }, library: { icon: iconBase + 'library_maps.png' }, info: { icon: iconBase + 'info-i_maps.png' } };

function addMarker(feature) { var marker = new google.maps.Marker({ position: feature.position, icon: icons[feature.type].icon, map: map }); }

暫無
暫無

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

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