簡體   English   中英

如何為我當前的標記設置自定義標記?

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

如何為我當前的標記設置自定義標記?

我嘗試了此鏈接,但對我而言不起作用如何為Google Maps API v3創建帶有自定義圖標的標記?

這是我的代碼

      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,

               });
           }

       }

添加一個帶有指向圖像鏈接的全局變量:

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

要更改大小/比例等,請修改代碼以包括:

  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
  }

添加標記時,請使用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/

暫無
暫無

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

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