google map API 地址查询
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>
无标题文档
</title>
<script type=”text/javascript” src=”http://maps.google.com/maps/api/js?sensor=false“>
</script>
<script type=”text/javascript”>
var geocoder;
var map;
var query = “北京 东直门”;
function initialize() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById(“map_canvas”), myOptions);
codeAddress();
}
function codeAddress() {
var address = query;
geocoder.geocode({
\’address\’: address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var infowindow = new google.maps.InfoWindow({
content: “<b>地址:</b>” + address
});
infowindow.open(map, marker);
} else {
alert(“未能解析该地址的原因: ” + status);
}
});
}
function googleMapApi(){
query = document.getElementById(“google”).value;
initialize();
}
</script>
</head>
<body onload=”initialize()”>
<input type=”text” id=”google” /> <input type=”button” id=”button” value=”click” onclick=”googleMapApi()” />
<div id=”map_canvas” style=”width:400px; height:400px”></div>
</body>