代码之家  ›  专栏  ›  技术社区  ›  Nikolas

Android Marker的图标

  •  0
  • Nikolas  · 技术社区  · 11 年前

    嗨,我有一段代码,每当我按下添加标记按钮时,它都会在地图上添加标记。每次在地图上添加标记时,我如何更改标记图标?非常感谢。

       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);
      }
    
    1 回复  |  直到 11 年前
        1
  •  2
  •   Joshua Alger    11 年前

    您可以使用谷歌的自定义地图标记,例如他们提供的以下代码片段:

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

    为了在用户每次添加标记时创建一个新图标,您可以创建一个图像位置数组,然后在每次用户添加新图标时遍历该数组。以下是关于谷歌自定义标记的更多文档:

    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 }); }