【问题标题】:geo-autocomplete not work after page refresh页面刷新后地理自动完成功能不起作用
【发布时间】:2012-10-01 18:59:26
【问题描述】:

我在可能的 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>

【问题讨论】:

    标签: javascript asp.net google-maps google-maps-api-3 asp-classic


    【解决方案1】:

    谢谢大家,我花了 4 个小时在 google 上终于找到了这个问题的答案,这很简单

    在您的 Page_load() 上使用此代码会帮助您

     ScriptManager.RegisterStartupScript(Page, this.GetType(), "delCty", "delCity();", true);
    

    这里“delCty”是键“delCity()”是函数名。是的意思是我给出函数的函数名称

         <script type="text/javascript">
        function delCity() 
    {
    }
    

    享受编码。我想这会对你有所帮助

    【讨论】:

      【解决方案2】:

      我不确定这是否与我曾经经历过的情况相同,但您可以试试这个: 如果纬度和/或纬度未设置(这意味着如果它没有任何值),我的 JavaScript 根本不起作用。所以我添加了一个条件(代码不是任何特定的编程语言),我的问题就消失了:

      If Latitude = "" then Latitude = 0
      If Langitude = "" then Langitude = 0
      

      【讨论】:

      • 问题,因为在回发后会出现这个问题。意味着当我的更新面板更新然后停止工作
      猜你喜欢
      • 1970-01-01
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 2017-02-28
      • 2020-11-14
      相关资源
      最近更新 更多