i am getting city state by entering zipcode using google map api my code is below,
google map api link,
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
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>
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>
EDITED:
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>
how would i get the auto complete city state when i put zip code in "txtZip" ??
Hopes for your suggestions
Thanks