Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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
Javascript 是否可以在谷歌地图api v3中添加个人位置以自动完成?_Javascript_Jquery_Google Maps Api 3_Google Places Api - Fatal编程技术网

Javascript 是否可以在谷歌地图api v3中添加个人位置以自动完成?

Javascript 是否可以在谷歌地图api v3中添加个人位置以自动完成?,javascript,jquery,google-maps-api-3,google-places-api,Javascript,Jquery,Google Maps Api 3,Google Places Api,我想使用自动完成谷歌搜索,但我想介绍一些个人的地方 这是我用来添加搜索位置的代码,但onclick不起作用: $(".pac-container").append('<div id="areasearch' + e + '" class="pac-item areasearch" style="display:none" onclick="clickOneAreaLocalizar(\'' + $(this).text() + '\')"><span class="pac-ic

我想使用自动完成谷歌搜索,但我想介绍一些个人的地方

这是我用来添加搜索位置的代码,但onclick不起作用:

$(".pac-container").append('<div id="areasearch' + e + '" class="pac-item areasearch" style="display:none" onclick="clickOneAreaLocalizar(\'' + $(this).text() + '\')"><span class="pac-icon pac-icon-areas"></span><span class="pac-item-query"><span class="pac-matched"></span>' + $(this).text() + '</span> <span>Area</span></div>');
我给大家举了个例子,让大家更好地理解我想要什么

结果qwerty有一个onclick,但不起作用

有人知道怎么做吗

谢谢:)

我希望这会有所帮助

    $(document).ready(function(){

  var mapOptions = {
       zoom: 10,
       mapTypeId: google.maps.MapTypeId.ROADMAP,
       center: new google.maps.LatLng(41.06000,28.98700)
     };

  var map = new google.maps.Map(document.getElementById("map"),mapOptions);

  var geocoder = new google.maps.Geocoder();  
     searchBoxMapAddress = function () {

        // Create the search box and link it to the UI element.
        var input = /** @type {HTMLInputElement} */(document.getElementById('searchbox')); 

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

        // Listen for the event fired when the user selects an item from the
        // pick list. Retrieve the matching places for that item.
         google.maps.event.addListener(searchBox, 'place_changed', function () {

                    var places = searchBox.getPlace(); 


                    // For each place, get the icon, place name, and location.

                    var bounds = new google.maps.LatLngBounds();

                    bounds.extend(places.geometry.location); 

                    map.fitBounds(bounds);


         });

        // Bias the SearchBox results towards places that are within the bounds of the
        // current map's viewport.
        google.maps.event.addListener(map, 'bounds_changed', function () {
            var bounds = map.getBounds();
            searchBox.setBounds(bounds);
        });

    }
    setTimeout(function(){
    $(".pac-container").append('<div id="areasearch" class="pac-item areasearch" onclick="alert(\'make onclick\')"><span class="pac-icon pac-icon-areas"></span><span class="pac-item-query"><span class="pac-matched"></span>qwerty</span> <span>Area</span></div>');
    }, 500);
     searchBoxMapAddress();
     });
$(文档).ready(函数(){
变量映射选项={
缩放:10,
mapTypeId:google.maps.mapTypeId.ROADMAP,
中心:新google.maps.LatLng(41.06000,28.98700)
};
var map=new google.maps.map(document.getElementById(“map”)、mapOptions);
var geocoder=new google.maps.geocoder();
searchBoxMapAddress=函数(){
//创建搜索框并将其链接到UI元素。
var input=/**@type{HTMLInputElement}*/(document.getElementById('searchbox');
var searchBox=new google.maps.places.Autocomplete(/**@type{HTMLInputElement}*/(输入),{types:['geocode']});
//侦听当用户从中选择项目时激发的事件
//选择列表。检索该项目的匹配位置。
google.maps.event.addListener(搜索框,'place\u changed',函数(){
var places=searchBox.getPlace();
//对于每个位置,获取图标、地名和位置。
var bounds=new google.maps.LatLngBounds();
扩展(places.geometry.location);
映射边界(bounds);
});
//将搜索框结果偏向在搜索范围内的位置
//当前地图的视口。
google.maps.event.addListener(映射,'bounds_changed',函数(){
var bounds=map.getBounds();
searchBox.setBounds(边界);
});
}
setTimeout(函数(){
$(“.pac容器”).append('qwerty区域');
}, 500);
searchBoxMapAddress();
});

您可以使用此

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

                setTimeout(function(){
                    $(".pac-container").append('<div id="are" class="pac-item" onmousedown="alert(\'Yes workingt\')"><span class="pac-icon icon-airport"></span><span class="pac-item-query"><span class="pac-matched"></span>sample Address</span> <span>it\'s Working</span></div>');
                }, 500);
var autocomplete=new google.maps.places.autocomplete(document.getElementById('yoursautocomplete');
setTimeout(函数(){
$(“.pac容器”).append('sample Address's Working');
}, 500);

我不这么认为,我尝试过的唯一“过滤器”是按国家和地图边界编辑:实际上,请在最底部查看:我想我曾经读过,您可能无法修改、重新排序或将自定义结果添加到自动完成,但我不知道我在哪里读到:(使用
onmousedown
而不是
onclick
,单击将被一个可能的副本取消,请参见上面的完整文档和工作解决方案。非常糟糕和未文档化的解决方案。此处相同。丑陋和未文档化。
var autocomplete = new google.maps.places.Autocomplete(document.getElementById('YourAutocomplete'));

                setTimeout(function(){
                    $(".pac-container").append('<div id="are" class="pac-item" onmousedown="alert(\'Yes workingt\')"><span class="pac-icon icon-airport"></span><span class="pac-item-query"><span class="pac-matched"></span>sample Address</span> <span>it\'s Working</span></div>');
                }, 500);