如何使用 place_changed google api 的 placekicker 事件?
how to use place_changed event of placekicker of google api?
我快完成了,但我面临一个问题,这是我的问题:-
I have successfully implement the placekicker with uk country only. Here is my code:-
Input location here:<input id="searchTextField" type="text" size="50">
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script>
var pac_input = document.getElementById('searchTextField');
$(function() {
var options = {
componentRestrictions: {
country: 'uk' //PUT YOUR COUNTRY CODE HERE!!
}
};
var autocomplete = new google.maps.places.Autocomplete(pac_input, options);
});
当我 运行 上面的代码时,它只会显示英国结果,即是正确的,但是当我在上面的代码中添加更多功能时,它会显示整个国家/地区的记录。添加的代码在这里:-
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('searchTextField'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
alert(mesg);
});
});
</script>
当我添加这段代码时,它会给出我从 placepicker select 得到的每个地方的经纬度.请帮我。我做错了什么。提前致谢:)
尝试在自动完成功能中传递选项
var options = {
componentRestrictions: {
country: 'uk' //PUT YOUR COUNTRY CODE HERE!!
}
};
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('searchTextField'), options ); //// options added
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
alert(mesg);
});
});
我快完成了,但我面临一个问题,这是我的问题:-
I have successfully implement the placekicker with uk country only. Here is my code:-
Input location here:<input id="searchTextField" type="text" size="50">
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script>
var pac_input = document.getElementById('searchTextField');
$(function() {
var options = {
componentRestrictions: {
country: 'uk' //PUT YOUR COUNTRY CODE HERE!!
}
};
var autocomplete = new google.maps.places.Autocomplete(pac_input, options);
});
当我 运行 上面的代码时,它只会显示英国结果,即是正确的,但是当我在上面的代码中添加更多功能时,它会显示整个国家/地区的记录。添加的代码在这里:-
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('searchTextField'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
alert(mesg);
});
});
</script>
当我添加这段代码时,它会给出我从 placepicker select 得到的每个地方的经纬度.请帮我。我做错了什么。提前致谢:)
尝试在自动完成功能中传递选项
var options = {
componentRestrictions: {
country: 'uk' //PUT YOUR COUNTRY CODE HERE!!
}
};
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('searchTextField'), options ); //// options added
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
alert(mesg);
});
});