【问题标题】:Use Bootstrap Glyphicon as a Google Maps Marker使用 Bootstrap Glyphicon 作为 Google 地图标记
【发布时间】:2014-07-11 16:25:59
【问题描述】:

为此奋斗了很久。我想使用 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
    });      

如果有人可以举个例子指导我吗?

【问题讨论】:

标签: javascript google-maps twitter-bootstrap-3 glyphicons


【解决方案1】:

首先,您需要 Glyphicons 作为矢量,您可以在此处购买:http://glyphicons.com/

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

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

Google 示例代码如下:

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

【讨论】:

    猜你喜欢
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 2014-09-03
    • 2020-02-21
    相关资源
    最近更新 更多