【发布时间】:2012-10-15 05:38:06
【问题描述】:
我正在尝试通过使用 base64 编码字符串在 Google 地图上使用自定义标记。不知何故,它不起作用。
【问题讨论】:
标签: google-maps base64 google-maps-markers
我正在尝试通过使用 base64 编码字符串在 Google 地图上使用自定义标记。不知何故,它不起作用。
【问题讨论】:
标签: google-maps base64 google-maps-markers
尝试如下操作:
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: 'hello',
id: 'hehehe',
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAA..."
});
编辑:只是补充:如果你使用服务器端语言来生成 js,你总是可以插入一些 PHP/Python/任何代码来加载图像并将其转换为它的 base64 表示。
类似(PHP 后端):
$path = 'path/to/my/image.ext';
$info = getimagesize($info);
$ext = ($info[2]);
$data = file_get_contents($path);
$encoded = 'data:image/' . $ext . ';base64,' .base64_encode($data);
然后(前端):
var marker = new google.maps.Marker({
//...
icon: '<?=$encoded;?>'
});
【讨论】: