<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<style>
body { margin: 0; padding: 10px; }
</style>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=zh_CN"></script>
<script>
var map, geocoder,marker;
function initialize() {
var latlng = new google.maps.LatLng(29.56301,106.551557);
var options = {
zoom: 11,
center: latlng,
disableDefaultUI: true,
panControl: true,
zoomControl: true,
mapTypeControl: true,
scaleControl: true,
streetViewControl: false,
overviewMapControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), options);
geocoder = new google.maps.Geocoder();
marker = new google.maps.Marker({
map: map,
position: latlng,
draggable: true
});
geocoder.geocode({latLng: latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[3]) {
document.getElementById("map_address").value = results[3].formatted_address;
}
}
});
}
function search() {
if (!map) return;
var address=document.getElementById("map_address").value;
geocoder.geocode({address : address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//map.setZoom(11);
map.setCenter(results[0].geometry.location);
marker.setPosition(results[0].geometry.location);
} else {
alert("没有找到: " + address);
}
});
}
function getbjd()
{
var center = map.getCenter().lat() + ',' + map.getCenter().lng(),
zoom = map.getZoom(),
maptype = map.getMapTypeId(),
markers=marker.getPosition().lat() + ',' + marker.getPosition().lng();
var url = 'http://maps.googleapis.com/maps/api/staticmap';
url += '?center=' + encodeURIComponent(center);
url += '&zoom=' + encodeURIComponent(zoom);
url += '&size=600x400';
url += '&maptype=' + encodeURIComponent(maptype);
url += '&markers=' + encodeURIComponent(markers);
url += '&language=zh_CN';
url += '&sensor=false';
document.getElementById("imgurl").value=url;
document.getElementById("simg").src=url;
}
</script>
</head>
<body onload="initialize();">
<div>地址 <input id="map_address" name="address" value="" style="200px;" />
<input type="button" onclick="search()" name="searchBtn" value="搜索" />
</div>
<table width='100%'>
<tr>
<td width='600'><div id="map_canvas" style="600px; height:400px;"></div></td>
<td><input type="button" onclick="getbjd()" name="getBtn" value="生成静态图" /></td>
<td><img src="" width='600' height='400' id='simg' /></td>
</tr>
</table>
<textarea id='imgurl' style='600px;height:50px;'></textarea>
=
</body>
</html>