简体   繁体   English

Android Marker的图标

[英]Android Marker's icons

Hi I have this code which adds a marker on the map every time I hit the add marker button. 嗨,我有这个代码,每次点击添加标记按钮时,都会在地图上添加一个标记。 Any advice of how I could change the markers icon everytime that a marker is added on the map ? 有关如何在地图上添加标记时每次更改标记图标的任何建议吗? Many thanks. 非常感谢。

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

You can use Google's custom map markers such as the following code snippet they provide: 您可以使用Google的自定义地图标记,例如他们提供的以下代码段:

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

In order to create a new icon every time a user adds a marker you could create an array of image locations and then traverse through the array every time the user added a new one. 为了在每次用户添加标记时创建新图标,您可以创建图像位置数组,然后在每次用户添加新图像时遍历数组。 Here is some more documentation on Google's custom markers: 以下是有关Google自定义标记的更多文档:

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

You could also define specific markers for specific features and pass the feature as a parameter. 您还可以为特定要素定义特定标记,并将该要素作为参数传递。 Google also provides some sample code for this functionality: 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