gpt4 book ai didi

javascript - 使用 Bootstrap Glyphicon 作为谷歌地图标记

转载 作者:搜寻专家 更新时间:2023-11-01 04:36:57 24 4
gpt4 key购买 nike

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

谁能举个例子指导我?

最佳答案

首先,您需要 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
});
}

关于javascript - 使用 Bootstrap Glyphicon 作为谷歌地图标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23810108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com