简体   繁体   English

如何为我当前的标记设置自定义标记?

[英]how to set custom marker for my current marker?

how to set custom marker for my current marker? 如何为我当前的标记设置自定义标记?

i tried this link but this doesn't work for me How do you create a Marker with a custom icon for google maps API v3? 我尝试了此链接,但对我而言不起作用如何为Google Maps API v3创建带有自定义图标的标记?

here my code 这是我的代码

      var markers = [
       {
           "lat": '3.214608',
           "lng": '101.639114',
       },
       {
           "lat": '3.214790',
           "lng": '101.640928',
       }
       ];

       window.onload = function () {
           LoadMap();
       }

       function LoadMap() {
           var mapOptions = {
               center: { lat: 3.214608, lng: 101.639114},
               zoom: 16,
               mapTypeId: google.maps.MapTypeId.ROADMAP
           };
           var map = new google.maps.Map(document.getElementById("map"), mapOptions);

           var infoWindow = new google.maps.InfoWindow();

           for (var i = 0; i < markers.length; i++) {
               var data = markers[i];
               var myLatlng = new google.maps.LatLng(data.lat, data.lng);
               var marker = new google.maps.Marker({
                   position: myLatlng,
                   map: map,

               });
           }

       }

add a global variable with a link to the image: 添加一个带有指向图像链接的全局变量:

var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png';

To change the size / scale etc modify the code to include: 要更改大小/比例等,请修改代码以包括:

  var icon = {
    url: image,
    scaledSize: new google.maps.Size(50, 50), // scaled size
    origin: new google.maps.Point(0, 0), // origin
    anchor: new google.maps.Point(0, 0) // anchor
  }

When adding the marker use the icon variable, and assign to the icon variable 添加标记时,请使用icon变量,并分配给icon变量

 marker = new google.maps.Marker({
    map: map,
    draggable: true,
    animation: google.maps.Animation.DROP,
    position: simplerweb,
    icon: icon// assign image here
  });

JSFiddle: https://jsfiddle.net/cmjcs5eL/18/ JSFiddle: https ://jsfiddle.net/cmjcs5eL/18/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM