Google Maps Api

paolo9785

我在使用Google Maps api集成进行表单自动完成时遇到问题。我已经实施了它并且可以正常工作,直到我尝试按国家/地区限制。

<script>
function initialize() {

var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(40.802089, -124.163751)
);

var origin_input = document.getElementById('location');
//var isocode = document.getElementById('ISOcountry').val()

var options = {
bounds: defaultBounds,
types: ['(cities)'],
language: '<?php echo $lang['dataLanguage']?>',
//componentRestrictions: {country: isocode }
};


var autocomplete_origin = new google.maps.places.Autocomplete(origin_input, options);    
}

google.maps.event.addDomListener(window, 'load', initialize);

如果我取消注释componetRestrictions的2行,它将无法正常工作,我也不明白为什么。

var isocode = document.getElementById('ISOcountry').val()

从此处获取ISO国家/地区值:

你们有什么主意吗?

我也想优化直接从此处附加的另一个脚本获取ISO代码的脚本:

$.post('libs/jsonISOcountry.php', { country : val }, populateISOcountry, 'html');
function populateISOcountry(data) {
    $('#ISOcountry').html(data);
}

页面内容jsonISOcountry.php

//....DB connection.....
if (!empty($_POST['country'])) {
foreach ($conn->query("SELECT * FROM regions WHERE countryID=".$_POST['country']) as    $row3) {
$html = $row3['isocountry'] ; 

}
die($html);

预先感谢您的帮助

paolo9785

找出问题了!

var isocode = document.getElementById('ISOcountry').val() 

不在表单的隐藏字段上工作!

改变了这一点,并正常工作!

var isocode = document.getElementById('ISOcountry').value;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章