Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何为Google places在页面加载时自动完成触发place_changed事件_Jquery_Google Maps_Google Maps Api 3 - Fatal编程技术网

Jquery 如何为Google places在页面加载时自动完成触发place_changed事件

Jquery 如何为Google places在页面加载时自动完成触发place_changed事件,jquery,google-maps,google-maps-api-3,Jquery,Google Maps,Google Maps Api 3,我正在使用GoogleMapAPI,我在页面加载时从查询字符串中填充位置,但它会打开选择列表以手动选择它(屏幕:)。 我只想在设置message_city的值(来自查询字符串)后在pageload上触发place_changed事件,以便其他函数可以调用(手动选择位置后调用) 我不确定我是否完全理解您需要什么,但如果您想触发事件,可以使用google.maps.event.trigger(autocomplete,'place_changed')。这应该能奏效 如果有帮助,请告诉我。我不确定我是

我正在使用GoogleMapAPI,我在页面加载时从查询字符串中填充位置,但它会打开选择列表以手动选择它(屏幕:)。 我只想在设置message_city的值(来自查询字符串)后在pageload上触发place_changed事件,以便其他函数可以调用(手动选择位置后调用)


我不确定我是否完全理解您需要什么,但如果您想触发事件,可以使用
google.maps.event.trigger(autocomplete,'place_changed')。这应该能奏效


如果有帮助,请告诉我。

我不确定我是否确切了解您需要什么,但如果您想触发事件,可以使用
google.maps.event.trigger(自动完成,'place_changed')。这应该能奏效


如果有帮助,请告诉我。

是的,我正在尝试相同的操作,但它正在打开选择列表(屏幕截图:),但我需要被选中它的第一个值是的,我正在尝试相同的操作,但它正在打开选择列表(屏幕截图:),但我需要被选中它的第一个值
geocoder = new google.maps.Geocoder();

cityac = new google.maps.places.Autocomplete( (document.getElementById('message_city')), { types: ['geocode'], componentRestrictions: {country:"GB"} });

google.maps.event.addListener(cityac, 'place_changed', function() { city_select(); });

function city_select() {
        var city = jQuery("#message_city").val();

        var place = cityac.getPlace();
        if ((place.address_components[1].short_name == 'London') || (jQuery('#message_city').val() == 'London, United Kingdom')) {
            jQuery('#result_info').val('<br />London Not Covered ');
            jQuery('#result').val('no');
        } else {
            geocoder.geocode({'address': city}, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    var search = results[0].geometry.location;
                    var mindist = parseInt(10000);
                    var closest = 0;
                    var town = '';

                    for (var i = 0; i < locations.length; i++) {
                        var exp = locations[i].split('#');
                        var loc = new google.maps.LatLng(exp[1], exp[2])
                        var distance = calcDistance(loc, search);
                        var miles = parseInt((distance * 0.621371192).toFixed(2));

                        if (mindist > miles) {
                            mindist = miles;
                            closest = i;
                            nohour = exp[3];
                            town = exp[0];
                            radius = exp[5];

                            if (radius == '') {
                                radius = 30;
                            }
                            else {
                                radius = parseInt(radius);
                            }
                        }

                    }
                    if (mindist <= radius) {
                        jQuery('#result_info').val('Closest Location is ' + town + ' | ' + mindist + ' miles');
                        jQuery('#result_city').val(town);
                        jQuery('#result').val('yes');

                        if (nohour == '1') {
                            //alert('This location has a minimum 2 hour time');
                            jQuery("#serviceHrs option[value='1']").remove();
                            jQuery("#serviceHrs").parent().after("<div class='infomsg' style='color:#ff0099;margin-bottom: 0;'>This location has a minimum of 2 hours.</div>");
                        }
                        else if (nohour == '0') {
                            jQuery(".infomsg").remove();
                            if (jQuery("#serviceHrs option:contains('1')").length == 0) {
                                jQuery("#serviceHrs").prepend(new Option("1 Hour", "1"));
                            }
                        }
                    } else {
                        jQuery('#result_info').val('<br />Closest Location is ' + town + ' | ' + mindist + ' miles, outside the ' + radius + ' mile zone of any current.');
                        jQuery('#result').val('no');
                    }
                }
            })
        }
    }
google.maps.event.trigger(cityac, 'place_changed');