使用Bootstrap Glyphicon作为Google Maps Marker

idr*_*fer 5 javascript google-maps glyphicons twitter-bootstrap-3

很长一段时间以来一直在努力争取.我想使用Bootstrap glyphicon作为谷歌地图标记图像.以下是我的谷歌地图标记的javascript代码:

var image = {
    src: '<i class="glyphicon glyphicon-move"></i>',       
    size: new google.maps.Size(24, 24), 
    origin: new google.maps.Point(0,0),   
    anchor: new google.maps.Point(12,12)
    };
var marker = new google.maps.Marker({
        draggable: true,          
        icon: image,   
        title: 'Drag to move to new location',
        raiseOnDrag: false
    });      
Run Code Online (Sandbox Code Playgroud)

如果有人能用一个例子来指导我吗?

Ale*_*ove 4

首先,您需要 Glyphicons 作为载体,您可以在这里购买:http ://glyphicons.com/

使用 Javascript API 版本 3,您可以使用 SVG 路径,如此处文档中所述:

https://developers.google.com/maps/documentation/javascript/symbols#add_to_marker

谷歌示例代码如下:

// This example uses SVG path notation to add a vector-based symbol
// as the icon for a marker. The resulting icon is a star-shaped symbol
// with a pale yellow fill and a thick yellow border.

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {lat: -25.363882, lng: 131.044922}
  });

  var goldStar = {
    path: 'M 125,5 155,90 245,90 175,145 200,230 125,180 50,230 75,145 5,90 95,90 z',
    fillColor: 'yellow',
    fillOpacity: 0.8,
    scale: 1,
    strokeColor: 'gold',
    strokeWeight: 14
  };

  var marker = new google.maps.Marker({
    position: map.getCenter(),
    icon: goldStar,
    map: map
  });
}
Run Code Online (Sandbox Code Playgroud)