读书人

googlemap

发布时间: 2012-10-30 16:13:35 作者: rapoo

google地图
早些天申请了n个key,在本地行,后来放到服务器上就每次打开页面报无效key,提示重新申请。看了下google的说明文档,后来用顶级域名注册了一个key,终于可以看到地图了。((((邮箱是:手机号码,密码是手机号码加。com。))));
用google地图是步骤如下:
1、<script type="text/javascript">
var map = null;
var geocoder = null;

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
//map.setCenter(new GLatLng(39.917, 116.397), 13);
geocoder = new GClientGeocoder();//对象来访问地理译码器
}
showAddress("$coupon.address");

}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
//map.setCenter(new GLatLng(39.917, 116.397), 13);
$("#map_canvas").hide();
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.bindInfoWindow(document.getElementById("address_div"));
}
}
);
}
}
</script>

在显示页写上这些,并在div中显示。


2、申请一个key,在页面的head中写下那个申请的key的js代码。
3、在页面加载完成时,执行initialize() 函数。可以采用:<body onload="initialize()">方式来加载。

读书人网 >Web前端

热点推荐