2017-07-04 66 views
0

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

我想這鏈接,但並不對我的工作How do you create a Marker with a custom icon for 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, 

       }); 
      } 

     } 
+1

限定 「當前的」 標誌物。點擊一個? –

+0

表示紅色默認標記 –

回答

0

添加一個全局變量與鏈接的圖像:

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 
    } 

當添加所述標記使用圖標可變的,並且分配給圖標可變

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/

+0

如果我想修改圖標大小,該怎麼辦? –

相關問題