我想通过自动完成 Google API 使用地址、城市等搜索邮政编码。我正在使用这样的代码。它提供了所有位置和地点的详细信息,但我只需要邮政,如果有任何建议,请提供。
<!DOCTYPE html>
<html>
<head>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes /base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://xilinus.com/jquery-addresspicker/src/jquery.ui.addresspicker.js">
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
<style type="text/css">
#map {
border: 1px solid #DDD;
width:300px;
height: 300px;
float:left;
margin: 0px 0 0 10px;
-webkit-box-shadow: #AAA 0px 0px 15px;
}
div {
font-family: Arial;
font-size: 10pt;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
var geocoder = new google.maps.Geocoder();
$("#addresspicker").autocomplete({
source: function (request, response) {
geocoder.geocode({ address: request.term }, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
response($.map(results, function(result) {
if ($.inArray("street_address", result.types) >= 0) {
return result.formatted_address;
}
}));
}
});
},
select: function (event, ui) {
var parts = ui.item.label.split(",")
, address1 = parts[0]
, address2 = parts.slice(1).join(",").trim();
$("#postal").val(address1 + "\n" + address2);
}
});
});
$(function() {
var addresspicker = $("#addresspicker").addresspicker();
var addresspickerMap = $( "#addresspicker_map" ).addresspicker({
elements: {
map: "#map",
lat: "#lat",
lng: "#lng",
locality: '#locality',
country: '#country'
}
});
var gmarker = addresspickerMap.addresspicker( "marker");
gmarker.setVisible(true);
addresspickerMap.addresspicker( "updatePosition");
});
</script>
</head>
<body>
<div>
<label>Address : </label><input id="addresspicker" />
</div>
<br/>
<br/>
<div>
<div>
<label>Address : </label> <input id="addresspicker_map" /> <br/>
<label>Locality: </label> <input id="locality" disabled=disabled> <br/>
<label>Country: </label> <input id="country" disabled=disabled> <br/>
<label>Latitude: </label> <input id="lat" disabled=disabled> <br/>
<label>Longitude: </label> <input id="lng" disabled=disabled> <br/>
<label>postal: </label> <input id="postal" disabled=disabled> <br/>
</div>
<br/>
<div id="map"></div>
</div>
</body>
</html>
提前致谢.......