Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.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
Google maps 谷歌地图api为国家自动完成_Google Maps_Autocomplete_Google Maps Autocomplete - Fatal编程技术网

Google maps 谷歌地图api为国家自动完成

Google maps 谷歌地图api为国家自动完成,google-maps,autocomplete,google-maps-autocomplete,Google Maps,Autocomplete,Google Maps Autocomplete,我只想得到地址在特定的国家,如果它是选择。我的代码是: var country=""; $("select[name='country_id']").change(function () { co=$("select[name='country_id']").val(); }); function initialize() { var options={}; if(country){ options =

我只想得到地址在特定的国家,如果它是选择。我的代码是:

var country="";
    $("select[name='country_id']").change(function () {
        co=$("select[name='country_id']").val();

    });
    function initialize() {
        var options={};
        if(country){
         options = {
                types: ['geocode'],
                componentRestrictions: {country: country}
            };
        }else{
            options = {
                types: ['geocode']
            };
        }

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

        google.maps.event.addListener(autocomplete, 'place_changed', function () {
        //...
        });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
但我的国家价值总是空的。
我如何处理国家以获得其价值?请帮帮我。谢谢

每次使用新国家/地区
onchange

JS


country=$(“选择[name='country_id'])).val()
而不是
co=$(“选择[name='country\u id'])。val()是,但它也不起作用:
var country=“”$(“选择[name='country\u id']).change(函数(){country=$(“选择[name='country\u id'])).val();});函数init(){alert(country);var input=document.getElementById('locationTextField');var autocomplete=new google.maps.places.autocomplete(input);}google.maps.event.adddomstener(窗口,'load',init)警报显示页面加载后不显示任何内容的一次。它无助于我在出现问题的地方添加工作示例
var country = "";
$("select[name='country_id']").change(function() {
  country = $("select[name='country_id']").val();
  $('#searchTextField').attr('placeholder','search form '+$("select[name='country_id'] option:selected").text())
  $('#input').show();
  initialize()
});

function initialize() {
  var input = document.getElementById('searchTextField');
  var options = {
    componentRestrictions: {
      country: country
    }
  };

  var autocomplete = new google.maps.places.Autocomplete(input, options);

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

    var place = autocomplete.getPlace();
    var lat = place.geometry.location.lat();
    var long = place.geometry.location.lng();
    alert(lat + ", " + long);

  });
}