【问题标题】:Android Marker's iconsAndroid Marker 的图标
【发布时间】:2014-03-04 16:11:47
【问题描述】:

您好,我有这段代码,每次我点击添加标记按钮时都会在地图上添加一个标记。关于每次在地图上添加标记时如何更改标记图标的任何建议?非常感谢。

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

【问题讨论】:

    标签: javascript icons markers


    【解决方案1】:

    您可以使用 Google 的自定义地图标记,例如他们提供的以下代码 sn-p:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 2018-06-01
      • 2013-12-25
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 2013-06-14
      相关资源
      最近更新 更多