直接貼出代碼,這個可以在本地創建一個html文件直接運行:
復制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Map</title>
<script charset="utf-8" src="http://map.soso.com/api/v2/main.js"></script>
<script>
function init() {
var center = new soso.maps.LatLng(31.15953,121.516035);
var map = new soso.maps.Map(
document.getElementById("container"),
{
center: center,//顯示地圖的中心位置
zoom: 15//顯示地圖的縮放級別
}
);
//地圖第一個mark的坐標
var position1 = new soso.maps.LatLng(31.15751,121.514061);
var marker = new soso.maps.Marker({
position: position1,
map: map
});
//地圖第二個mark的坐標
var position2 = new soso.maps.LatLng(31.160705,121.524017);
var marker = new soso.maps.Marker({
position: position2,
map: map
});
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://map.soso.com/api/v2/main.js?callback=init";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
</head>
<body onload="init()">
<div id="container" style="width:1000px; height:800px"></div>
</body>
</html>