Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 谷歌地图地理位置结果列表(非自动完成)_Jquery_List_Google Maps_Autocomplete - Fatal编程技术网

Jquery 谷歌地图地理位置结果列表(非自动完成)

Jquery 谷歌地图地理位置结果列表(非自动完成),jquery,list,google-maps,autocomplete,Jquery,List,Google Maps,Autocomplete,我有代码让地理编码定位像自动完成一样工作,但我需要的是结果打印在文本框下面的静态列表中,在文本框中,你写下你要查找的地址,而不是像自动完成一样,它在你写的时候显示,当你聚焦任何其他控件时关闭 最后,我只希望地理定位的结果在外部列表中,而不是自动完成。我在谷歌上搜索了好几天,仍然没有找到任何东西。所以,如果你们中有人知道如何做到这一点,我将不胜感激。也许这是一件简单的事情,但我对jquery的知识非常贫乏,我就是不懂那种语言 应用户要求: 以下是我在网页中使用的代码: <script typ

我有代码让地理编码定位像自动完成一样工作,但我需要的是结果打印在文本框下面的静态列表中,在文本框中,你写下你要查找的地址,而不是像自动完成一样,它在你写的时候显示,当你聚焦任何其他控件时关闭

最后,我只希望地理定位的结果在外部列表中,而不是自动完成。我在谷歌上搜索了好几天,仍然没有找到任何东西。所以,如果你们中有人知道如何做到这一点,我将不胜感激。也许这是一件简单的事情,但我对jquery的知识非常贫乏,我就是不懂那种语言

应用户要求:

以下是我在网页中使用的代码:

<script type="text/javascript">
 $().ready(function() {demo2();});

 // the select function uses the viewport of the chosen location to relocate the map
 function demo2() {
     var map = new google.maps.Map(document.getElementById("demo2_map"), { mapTypeId: google.maps.MapTypeId.ROADMAP });

     $('#demo2_location').geo_autocomplete({
        select: function(_event, _ui) {
            if (_ui.item.viewport) map.fitBounds(_ui.item.viewport);}
     });
 }

</script>
下面是我用来创建名为autocomplete.js的自动完成的代码:


谢谢。

提供更多信息和/或到您的实施的链接将非常有帮助。您好,andresf,谢谢您的评论。下面是问题的更多内容。
$.widget( "ui.geo_autocomplete", {
// setup the element as an autocomplete widget with some geo goodness added
_init: function() {
    this.options._geocoder = new google.maps.Geocoder; // geocoder object
    this.options._cache = {}; // cache of geocoder responses
    this.element.autocomplete(this.options);

    // _renderItem is used to prevent the widget framework from escaping the HTML required to show the static map thumbnail
    this.element.data('autocomplete')._renderItem = function(_ul, _item) {
        return $('<li></li>').data('item.autocomplete', _item).append(this.options.getItemHTML(_item)).appendTo(_ul);
    };
},

// default values
options: {
    geocoder_region: '', // filter to a specific region, e.g. 'Europe'
    geocoder_types: 'locality,political,country', // array of acceptable location types, see http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingAddressTypes
    geocoder_address: true, // true = use the full formatted address, false = use only the segment that matches the search term

    minLength: 3, // see http://jqueryui.com/demos/autocomplete/#option-minLength
    delay: 300, // see http://jqueryui.com/demos/autocomplete/#option-delay
    // callback function to get autocomplete results
    source: function(_request, _response) {
        if (_request.term in this.options._cache) {
            _response(this.options._cache[_request.term]);
        } else {
            var self = this;
            var _address = _request.term + (this.options.geocoder_region ? ', ' + this.options.geocoder_region : '');
            this.options._geocoder.geocode({'address': _address}, function(_results, _status) {
                var _parsed = [];
                if (_results && _status && _status == 'OK') {
                    var _types = self.options.geocoder_types.split(',');
                    $.each(_results, function(_key, _result) {
                        // if this is an acceptable location type with a viewport, it's a good result

                            if (self.options.geocoder_address) {
                                _place = _result.formatted_address;
                            } else {
                                // place is first matching segment, or first segment
                                var _place_parts = _result.formatted_address.split(',');
                                var _place = _place_parts[0];
                                $.each(_place_parts, function(_key, _part) {
                                    if (_part.toLowerCase().indexOf(_request.term.toLowerCase()) != -1) {
                                        _place = $.trim(_part);
                                        return false; // break
                                    }
                                });
                            }

                            _parsed.push({
                                value: _place,
                                label: _result.formatted_address,
                                viewport: _result.geometry.viewport
                            });

                    });
                }
                self.options._cache[_request.term] = _parsed;
                _response(_parsed);
            });
        }
    },
    // returns the HTML used for each autocomplete list item
    getItemHTML: function(_item) {                  
        return '<a>'+_item.label+'</a>';
    }
}
});