api官网:
http://api.map.soso.com/doc_v2/example.html?sample-geocoding-simple#8map
示例代码如下(保存为html打开可见效果):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>按关键字查询</title>
<script charset="utf-8" src="http://map.soso.com/api/v2/main.js"></script>
<script>
var geocoder,map,marker = null;
var init = function() {
var center = new soso.maps.LatLng(39.916527,116.397128);
map = new soso.maps.Map(document.getElementById('iCenter'),{
center: center,
zoom: 15
});
geocoder = new soso.maps.Geocoder({
complete : function(result){
map.setCenter(result.detail.location);
var marker = new soso.maps.Marker({
map:map,
position: result.detail.location,
title:result.detail.address+result.detail.location
});
},
error : function(result){
$("#iCenter").empty();
$("#iCenter").append("检索没有结果,原因: " + result);
}
});
}
function codeAddress() {
var address = "成都市金河路口宽窄巷子";
geocoder.getLocation(address);
}
var showmap = function()
{
init();
codeAddress();
}
</script>
</head>
<body οnlοad="showmap();">
<div id="iCenter" style="height:300px;width=661px "></div>
</body>
</html>