使用谷歌地图的IndexSizeError v3:使用google.maps.Marker [英] IndexSizeError using google maps v3: using google.maps.Marker
问题描述
我正在用jquery和google maps v3创建一个页面,我试图在Google地图上显示一个标记。出于某种原因,我得到一个错误的Firefox(和标记不显示在地图上):
错误: IndexSizeError:索引或大小为负数或大于所允许的数量源
文件:http://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/17/main.js
行:96
事实:
*在Safari
*如果我更改MarkerImage url的作品
我用来添加标记的代码如下:
<$ $ {$ b $ map:map,
icon:new google.maps.MarkerImage(
/ gfx / icons / poi.png,
new google.maps.Size(22,22),
new google.maps.Point(0,0),
google.maps.Point 11,11),
new google.maps.Size(22,22)),
position:point
});
我的测试可以在这里看到:
更精确:image /gfx/icons/poi.png不是22 x 22像素,而是30 x 30像素。所以要解决这个问题有三个解决方案:
$ ul
a)相应地改变第二个参数(大小为
google.maps。大小(30,30));
(scaledSize改为google.maps.Size(30,30));
参数(新的google.maps.Size(22,22)),它将调整标记
图像的大小。如果a)markerImage将被缩放到定义大小(22x22),在b)和c)的情况下,将会裁剪出22x22的图像b
的原始30x30大小。
I'm creating a page with jquery and google maps v3 and I'm trying to show a marker on a google maps. For some reason I'm getting an error with Firefox (and the marker isn't showing on the map):
Error: IndexSizeError: Index or size is negative or greater than the allowed amount Source
File: http://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/17/main.js
Line: 96
Facts: * It works in Safari * It works if I change the MarkerImage url
Code that I'm using to add the marker is the following:
var marker = new google.maps.Marker({
map: map,
icon: new google.maps.MarkerImage(
"/gfx/icons/poi.png",
new google.maps.Size(22,22),
new google.maps.Point(0,0),
new google.maps.Point(11,11),
new google.maps.Size(22,22)),
position: point
});
My test can be visible here:
It seems that the problem is in the google.maps.MarkerImage object, in the fifth (scaledSize) parameter to be exact in cases where the actual size of the image is not as defined in the code. For some reason Firefox cannot handle scaling if the image size is incorrectly defined and scaledSize matches actual size but doesn't match the image size.
to be more precise: image /gfx/icons/poi.png is not 22 x 22px but 30 x 30px. So to overcome this problem there are three solutions:
- a) change the second parameter accordingly (size to google.maps.Size(30,30));
- b) change the fifth parameter accordingly (scaledSize to google.maps.Size(30,30));
- c) remove the fifth parameter (new google.maps.Size(22,22)) that would resize the marker image.
in case of a) the markerImage will be scaled to the defined size (22x22), in case of b) and c) the 22x22 would be cropped out of the original 30x30 size.
这篇关于使用谷歌地图的IndexSizeError v3:使用google.maps.Marker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!