javascript Google 地图错误:未捕获的 InvalidValueError:setIcon:不是字符串;并且没有 url 属性;并且没有路径属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25750692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:56:52  来源:igfitidea点击:

Google Maps Error: Uncaught InvalidValueError: setIcon: not a string; and no url property; and no path property

javascriptjquerygoogle-maps

提问by Patrick Brown

I just started getting this error today for Google Maps:

我今天刚开始在谷歌地图上收到这个错误:

Uncaught InvalidValueError: setIcon: not a string; and no url property; and no path property

未捕获的 InvalidValueError: setIcon: not a string; 并且没有 url 属性;并且没有路径属性

I haven't changed any code in months.

几个月来我没有更改任何代码。

The error is happening on this page: http://gusmodern.com/pages/store-locator

此页面上发生错误:http: //gusmodern.com/pages/store-locator

Has anyone come across this before?

有没有人遇到过这个?

回答by Rob

I updated to the specific version reference https://maps.googleapis.com/maps/api/js?v=3&sensor=trueand the error went away. I had this across multiple of my geolocation websites and mobile apps.

我更新到特定版本参考https://maps.googleapis.com/maps/api/js?v=3&sensor=true并且错误消失了。我在我的多个地理定位网站和移动应用程序中都有过这种情况。

回答by Scott

I got the same error just recently in some of my code. Thanks to another question in the past, I realized that when I set the markers I needed to make sure the variables I was bringing in for the anchor and scaled size were float numbers and not coming in as strings. This must be a new requirement with a recent update.

我最近在我的一些代码中遇到了同样的错误。感谢过去的另一个问题,我意识到当我设置标记时,我需要确保我为锚点和缩放大小引入的变量是浮点数,而不是作为字符串输入。这必须是最近更新的新要求。

In my own code I changed

在我自己的代码中我改变了

currentIcon = {
            url: 'http://www.example.com/img/avatars/'+name+'.png',
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(aw,ah),
            scaledSize: new google.maps.Size(w,h)
        };

to

currentIcon = {
            url: 'http://www.example.com/img/avatars/'+name+'.png',
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(parseFloat(aw),parseFloat(ah)),
            scaledSize: new google.maps.Size(parseFloat(w),parseFloat(h))
        };

and it now works fine for me.

现在它对我来说很好用。

回答by user3560005

I had the same Problem with an icon as property of a MarkerWithLabel{}.

我在将图标作为 MarkerWithLabel{} 的属性时遇到了同样的问题。

The Solution:

解决方案:

var nullIcon = { url: '', size: new google.maps.Size(0, 0), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(0, 0) };

回答by Martin

Since two days I also experienced this problem. In my case I am setting a MarkerImage on the map with a null argument. This means that I am hiding markers on the map.

这两天我也遇到了这个问题。在我的例子中,我在地图上设置了一个 MarkerImage 并带有一个空参数。这意味着我在地图上隐藏了标记。

This worked before:

这以前有效:

markers = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location,
                icon: new google.maps.MarkerImage(null)
            });

Now this seems the solution:

现在这似乎是解决方案:

markers = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
            markers.setVisible(false);

Hope this helps. Good luck!

希望这可以帮助。祝你好运!