我在可能的 asp.net 应用程序中使用地理自动完成。我的问题是,当我第一次在我使用地理自动完成的文本框中写一些东西时,它会显示结果。但是我的页面上有一个自动回发文本框事件,当他们触发谷歌地理自动完成不起作用时,我用于谷歌自动完成的 html 是这样的:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../lib/jquery.autocomplete_geomod.js"></script>
<script type="text/javascript" src="../js/geo_autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="../lib/jquery.autocomplete.css" />
<script type="text/javascript">
$().ready(function() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('<%=map_canvas.ClientID %>'), myOptions);
// use all the autocomplete options as documented at http://docs.jquery.com/Plugins/Autocomplete
/* additional geo_autocomplete options:
mapkey : 'ABQ...' (required for Static Maps thumbnails, obtain a key for your site from http://code.google.com/apis/maps/signup.html)
mapwidth : 100
mapheight : 100
maptype : 'terrain' (see http://code.google.com/apis/maps/documentation/staticmaps/#MapTypes)
mapsensor : true or false
*/
$('#<%=txtPickupCity.ClientID %>').geo_autocomplete(new google.maps.Geocoder, {
mapkey: 'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBTIx7cuHpcaq3fYV4NM0BaZl8OxDxS9pQpgJkMv0RxjVl6cDGhDNERjaQ',
selectFirst: false,
minChars: 3,
cacheLength: 50,
width: 300,
scroll: true,
scrollHeight: 330
}).result(function(_event, _data) {
if (_data) map.fitBounds(_data.geometry.viewport);
});
});
</script>
<style>
.ac_results li img {
float: left;
margin-right: 5px;
}
</style>
这是我使用地理代码的文本框
<asp:TextBox ID="txtPickupCity" runat="server" MaxLength="50"
Width="140px"></asp:TextBox>