【问题标题】:google Places Autocomplete dropdown not triggering 'place_changed' event in iOS9 using ionic3google Places Autocomplete 下拉菜单未使用 ionic 3 在 iOS 9 中触发“place_changed”事件
【发布时间】:2019-04-21 03:31:38
【问题描述】:

这是示例代码,非常基本,但在 iOS 中不会触发“place_changed”

var input = document.getElementById('autocomplete');
        var autocomplete = new google.maps.places.Autocomplete(input);

        google.maps.event.addListener(autocomplete, 'place_changed', function(){
            mylocation = autocomplete.getPlace();
            alert(mylocation);
        })

尝试了这些解决方案:

1 : 从监听器中移除 自动完成

google.maps.event.addListener('place_changed', function()

2 : 添加 tappable 因为 pac-item 不是按钮,链接。

let list1 = document.querySelectorAll(".pac-item,.pac-container");

     console.log('pacIt', list1);

     for (let i = 0; i < list1.length; ++i) {
         list1[i].setAttribute('tappable', 'true');
     }

3:添加了needsclick

 let list2 = document.querySelectorAll(".pac-item, .pac-item span");

     console.log('pacIt', list2);

     for (let i = 0; i < list2.length; ++i) {
        list2[i].classList.add('needsclick');
    }

而且没有一个解决方案可以帮助我解决问题。

请任何人有干净的修复,请分享。

提前致谢。

【问题讨论】:

    标签: javascript google-maps ionic-framework google-places-api


    【解决方案1】:

    谷歌没有修复错误

    因此创建了我自己的自定义自动完成

    首先,初始化组件:

    this.customAutoComp = new google.maps.places.AutocompleteService(
                    {
                        componentRestrictions: { 'country': 'in' }
                    });
    

    下一个

     this.customAutoComp.getQueryPredictions({ input: value }, (results, status) => {
    
    
                                if (status == google.maps.places.PlacesServiceStatus.OK) {
    
    console.log(results); 
            }
        });
    

    将使用 UL、LI 或任何其他卡片样式在 UI 上填充结果。

    点击任意地址

    public clickAddress(address) {
    
     var geocoder = new google.maps.Geocoder();
    
     geocoder.geocode({ 'address': address}, (results, status) => {
                if (status == google.maps.GeocoderStatus.OK) {
    
     console.log(results);
    }
    });
    

    【讨论】:

      猜你喜欢
      • 2017-01-30
      • 2023-03-07
      • 2015-03-19
      • 2018-02-18
      • 2012-09-30
      • 1970-01-01
      • 2013-11-25
      • 2011-12-15
      • 1970-01-01
      相关资源
      最近更新 更多