Google 地图 V3 自定义标记在 IE 中不显示
我正想发这个帖子,后来我想通了。但无论如何我都会将其发布给其他需要它的人。吸取的教训是,如果您希望自定义标记图像在 IE 中工作,请使用 .ico 文件。 (顺便说一句,它在 Safari 中仍然无法正常工作,但这是另一个问题。)
我有一段时间遇到一个问题,即使用自定义图像创建的 Google Maps API V3 标记无法在 IE 或 Safari 中显示。它在我测试过的所有其他浏览器中都运行良好,但我们的大多数用户群仍然使用 IE,所以我需要解决这个问题。
这显然是一个已知问题(至少对谷歌来说),如谷歌支持线程中所示: http://www.google.com/support /forum/p/maps/thread?tid=26db8fd040386548&hl=en
我想知道是否有其他人遇到过这个问题或知道它的解决方法吗?
这是我创建的一个简单测试页面的 js,它演示了这个错误:
var map;
var latLng = new google.maps.LatLng(41.342, -84.932);
$(function() {
var myOptions = {
zoom: 17,
center: latLng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var newMarker = new google.maps.Marker({
map: map,
position: latLng,
icon: 'images/active_point.png'
});
});
修复:我将图像转换为 active_point.ico,这对于 IE 来说工作得很好。由于某种原因 IE 不喜欢我的 .png。
经过更多研究后,Safari 似乎必须作为特殊情况处理,因为它似乎不适用于 .ico 或 .png 标记图像。我只能使用 .jpg,这很烦人,因为它们不支持 Alpha 通道。
I was about to post this, then I figured it out. But I'll post it anyway for anyone else who needs it. The lesson learned is to use .ico files for custom marker images if you want them to work in IE. (As a side note, it's still not working right in Safari, but that is another issue.)
I've had an issue for a while now where Google Maps API V3 markers created using custom images do not display in IE or Safari. It works fine in every other browser I've tested, but most of our user base is still on IE so I need to get this fixed.
This is apparently a known issue (at least to Google), as indicated in this Google support thread:
http://www.google.com/support/forum/p/maps/thread?tid=26db8fd040386548&hl=en
I'm wondering if anyone else has run into this issue or knows of a workaround for it?
Here's the js from a simple test page I created, which demonstrates this bug:
var map;
var latLng = new google.maps.LatLng(41.342, -84.932);
$(function() {
var myOptions = {
zoom: 17,
center: latLng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var newMarker = new google.maps.Marker({
map: map,
position: latLng,
icon: 'images/active_point.png'
});
});
The fix: I converted the image to active_point.ico and that worked just fine for IE. For some reason IE doesn't like my .png.
After some more research it appears that Safari must be handled as a special case because it does not seem to work with .ico OR .png marker images. I've only gotten .jpgs to work, which is annoying because they don't support an alpha channel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
添加元标记
和此代码为 Google Api 代码
add metatag
& this code to Google Api code
另一种选择是使用 MarkerImage 类。
Another option is to use the MarkerImage class.
IE 必须需要特定的 PNG 文件。从 google api 的示例
apis.google.com
更新我的动态图标源修复了该问题:IE must want particular PNG files. Updating my dynamic icon source from the google api's sample
apis.google.com
fixed it:另一种可能性是将属性draggable = true添加到标记中:
不知道为什么这可以解决IE中的问题,检查此项
Another possibility is to add the property draggable = true to the markers:
Don't know why this solve the issue in IE, check this
创建自定义
Marker
时设置optimized: false
修复了我遇到的.svg
图标未出现在 IE 中的问题。请参阅此链接了解更多详细信息
Google 地图 SVG 标记不t 在 IE 上显示11
Setting
optimized: false
when creating a customMarker
fixed the problem I was getting with.svg
icons not appearing in IE.See this link for more details
Google Maps SVG marker doesn't display on IE 11