使用jquery-ui-map,我尝试使用个性化图标。我用这种方式工作很好:
$("#gmap_" + parent).gmap('addMarker', {
"id": "marker-"+m.id,
'position': new google.maps.LatLng(m.lat, m.lon),
'bounds':true,
'icon': '/images/'+m.icon
})因为我的图标只是一个网址。但是我想把我所有的图标放在一个精灵中,所以我必须设置其他选项:
$("#gmap_" + parent).gmap('addMarker', {
"id": "marker-"+m.id,
'position': new google.maps.LatLng(m.lat, m.lon),
'bounds':true,
'icon': new google.maps.MarkerImage( {
'url' : "http://crm.brunet.pro/images/markers.png",
'origin': new google.maps.Point(m.pos, 0),
'size' : new google.maps.Size(20, 34)
})
})我得到了这个错误:
GET http://mysite.com/[object%20Object] 400 (Bad Request)因此,图标选项看起来只接受一个字符串。但是您可以在api中看到它应该接受一个MarkerImage对象。
我做错了什么?
谢谢
发布于 2012-06-04 23:48:58
MarkerImage是使用最多五个参数创建的,比如MarkerImage(myUrl, size1, point1, point2),但您已经将其编写为一个对象参数。
我确实认为API文档在这样的情况下可能会令人困惑。看看这些例子:
https://developers.google.com/maps/documentation/javascript/overlays#ComplexIcons
var image = new google.maps.MarkerImage('images/beachflag.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(20, 32),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32));http://blog.mridey.com/2010/03/using-markerimage-in-maps-javascript.html (解释从精灵工作表加载)
没有提到size, origin, anchor,但是您需要尊重API文档中给出的顺序。
https://stackoverflow.com/questions/10884030
复制相似问题