java调用百度地图和谷歌地图

java调用百度地图:
示例代码如下(baidu.jsp):
<%@ page contentType="text/html; charset=gb2312"%>
<!DOCTYPE html>
<html>
	<head>
		<title>百度地图javascript</title>
		<script type="text/javascript">
function initialize() {
	var mp = new BMap.Map('map');
	mp.centerAndZoom(new BMap.Point(121.2134, 31.0576), 15);
}

function loadScript() {
	var script = document.createElement("script");
	script.src = "http://api.map.baidu.com/api?v=1.4&callback=initialize";
	document.body.appendChild(script);
}

window.onload = loadScript;
</script>
	</head>
	<body>
		<div id="map" style="width: 1500px; height: 1000px"></div>
	</body>
</html>

效果显示:
[img]

[/img]

java调用google地图:
实例代码如下(google.jsp):
<%@ page contentType="text/html; charset=gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:v="urn:schemas-microsoft-com:vml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=gb2312" />
		<title>谷歌地图javascript</title>
		<script
			src="http://ditu.google.com/maps?file=api&v=2&key=ABQIAAAAmZzPqf2aW-7Si6ot-HY9-hRhm3yhlCBaxy4FA8xZJReMAoDMwhQtB3B5zaWqCOSd_tjuCOoj9SsVZw"
			type="text/javascript">
</script>
		<script type="text/javascript">
function initialize() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(31.0576, 121.2134), 14);
	}
}
</script>
	</head>
	<body onload="initialize()" onunload="GUnload()" >
		<div id="map_canvas" style="width: 1500px; height: 1000px">
		</div>
	</body>
</html>


效果显示:
[img]

[/img]

猜你喜欢

转载自yangjianzhouctgu.iteye.com/blog/1845112