我有以下代码来构建这样的自定义谷歌地图标记:
mapa.markers[ind] = new google.maps.Marker({
position: mposition,
map:mapa.map,
title:mapa.json.markers[ind].timestamp,
icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+ind+"|000000|FFF",
});
使用此解决方案here,我正在尝试将此代码集成到上面但是出现语法错误?我做错了什么?
null, /* size is determined at runtime */
null, /* origin is 0,0 */
null, /* anchor is bottom center of the scaled image */
new google.maps.Size(42, 68)
以下是显示语法错误的更新代码:
mapa.markers[ind] = new google.maps.Marker({
position: mposition,
map:mapa.map,
title:mapa.json.markers[ind].timestamp,
icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+ind+"|000000|FFF",
null, /* size is determined at runtime */
null, /* origin is 0,0 */
null, /* anchor is bottom center of the scaled image */
new google.maps.Size(42, 68)
});
答案 0 :(得分:1)
您的语法不正确。
icon object应该像这样定义:
mapa.markers[ind] = new google.maps.Marker({
position: mposition,
map:mapa.map,
title:mapa.json.markers[ind].timestamp,
icon: {url:"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+ind+"|000000|FFF",
scaledSize:new google.maps.Size(42, 68)}
});
(感谢@andrewap测试它和jsfiddle)
不需要size
属性(它在图像加载时自动设置),除非您使用精灵,这不是这里的情况。