我的code如何自动完成市州通过输入邮编code到Java脚本附? [英] How To Auto Complete City State By Entering Zipcode Through Java Script My Code Attached?

查看:88
本文介绍了我的code如何自动完成市州通过输入邮编code到Java脚本附?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用谷歌地图API我的code是下面,输入地区code得到市州

i am getting city state by entering zipcode using google map api my code is below,

谷歌地图API的链接,

google map api link,

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>

脚本通过拉链code得到城市的状态,

Script for getting city state via zip code,

<script type="text/javascript">
   var zip ="34200";
    var lat;
    var lng;
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': zip }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            geocoder.geocode({'latLng': results[0].geometry.location}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[1]) {
                    var loc = getCityState(results);
                    document.getElementById("TextBox1").value=loc;
                }
            }
        });
        }
    }); 

function getCityState(results)
    {
        var a = results[0].address_components;
        var city, state;
        for(i = 0; i <  a.length; ++i)
        {
           var t = a[i].types;
           if(compIsType(t, 'administrative_area_level_1'))
              state = a[i].long_name; //store the state
           else if(compIsType(t, 'locality'))
              city = a[i].long_name; //store the city
        }
        return (city + ', ' + state)
    }

function compIsType(t, s) { 
       for(z = 0; z < t.length; ++z) 
          if(t[z] == s)
             return true;
       return false;
    }
</script>

在这里,我很难code拉链值34200无法从压缩文本框获得权利,但现在呈现城市状态的文本框TextBox1中如下图所示,

here i hard code zip value "34200" not getting from zip text box right now but showing city state in textbox "TextBox1" shown below,

<asp:TextBox ID="txtZip"  runat="server" ToolTip="Enter Zip"></asp:TextBox>
   <asp:TextBox ID="TextBox1" runat="server" ForeColor="Gray"></asp:TextBox>

编辑:

如何使用这个jQuery脚本与我的JS自动完成??

how to use this jquery script with my JS for auto complete??

<script>
  $(function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  });
  </script>

我怎么才能自动完成城市的状态,当我把拉链code在txtZip??

how would i get the auto complete city state when i put zip code in "txtZip" ??

的希望您的建议

感谢

推荐答案

从zip文本框中获取的价值就像你设置的城市。

Get the value from the zip textbox like you're setting the city.

var zip = document.getElementById("txtZip").value

希望这有助于

这篇关于我的code如何自动完成市州通过输入邮编code到Java脚本附?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆