Google 自动完成 Places API 错误 InvalidValueError

用户6179844
function wnw_set_google_autocomplete_my(){
    jQuery(gaaf_fields_my).each(function(){

        var autocomplete_my= new google.maps.places.Autocomplete(
        /** @type {HTMLInputElement} */(this),
        { types: ['geocode'] });
        // When the user selects an address from the dropdown,
        // populate the address fields in the form.

    });
}
jQuery(window).load(function(){
    wnw_set_google_autocomplete_my();
});

链接:http: //35.154.204.251/contact/

我已经在 wordpress 中安装了 Google 自动完成 Place api 并且我在控制台中收到 InvalidValueError 并且我无法找出问题,因为对我来说一切都很好。

西门

看看变量的值gaaf_fields_my当我放置一个断点时,我可以看到这个变量具有以下值

" [name="input_2"], [name="demo"], #input_2_2, #demo, .address, .demo"

问题是jQuery(gaaf_fields_my)作为第一个<li>元素返回一个具有类“地址”而不是<input>. 这会导致自动完成构造函数中出现异常,该构造函数期望输入元素作为参数,但您尝试在 上对其进行初始化<li>

在此处输入图片说明

在调用自动​​完成构造函数之前,您应该应用更好的选择器或在 jQuery 循环内部检查元素的标记名称:

 function wnw_set_google_autocomplete_my(){
     jQuery(gaaf_fields_my).each(function(){

         if (this.tagName.toLowerCase() === 'input') {

             var autocomplete_my= new google.maps.places.Autocomplete(
                 /** @type {HTMLInputElement} */(this),
                 { types: ['geocode'] });

         }
     });
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从 Google Places api 自动完成获取时区

Google Places 自动完成 Api 2019

Google Places API:了解Places自动完成响应的解析

Google Places Api,放置自动完成的mBound查询

iOS上的Google Places API自动完成功能

CORS和Google Maps Places自动完成API调用

如何获取自动完成TextView的Google Places API?

Google Places API自动完成获取城市列表

自动完成文字检视Google Places API

从Google Places API iOS访问结果以自动完成

Google Places机场自动完成

Google Maps自动完成InvalidValueError:不是HTMLInputElement的实例

Google Places 自动完成 Swift 3

根据Google Places API自动完成功能的类型结果进行过滤

使用新的Places API的自动完成预测

Google Maps错误不是latlng或latlngliteral invalidvalueerror

限制或延迟Google Places API的自动建议

Shinydashboard:Google地方信息自动完成功能。InvalidValueError:不是HTMLInputElement的实例

如何在Google Places API中针对Android中的自动完成预测获取特定国家/地区的结果?

Google Maps Places API V3自动完成-在输入时选择第一个选项

Google Places API错误-ApiException:9008:PLACES_API_INVALID_APP

google.maps.places。自动完成语言输出

Google Maps Places自动完成搜索任何位置

无法删除Google Places自动完成功能?

使用Angular为Google Places自动完成指定起始位置

在jQuery移动面板中集成Google Places(自动完成)

使用Google Places API时出现lat_lng错误

Google Places APi照片

Google Places API替代