<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>
<script>
var searchService,map,markers = [];
var init = function() {
var center = new soso.maps.LatLng(39.916527,116.397128);
map = new soso.maps.Map(document.getElementById('iCenter'),{
center: center,
zoomLevel: 13
});
searchService = new soso.maps.SearchService();
}
//清除地图上的marker
function clearOverlays(overlays){
var overlay;
while(overlay = overlays.pop()){
overlay.setMap(null);
}
}
function searchKeyword() {
var keyword = "宽窄巷子";
var region = "成都";
clearOverlays(markers);
var searchRequest = {
'keyword': keyword,
'region':region
};
var latlngBounds = new soso.maps.LatLngBounds();
searchService.search(searchRequest, function(results, status) {
if (status == soso.maps.SearchStatus.OK) {
var pois = results.pois;
for(var i = 0,l = pois.length;i < l; i++){
var poi = pois[i];
latlngBounds.extend(poi.latLng);
var marker = new soso.maps.Marker({
map:map,
position: poi.latLng,
title: poi.address+poi.latLng
});
var decor = new soso.maps.MarkerDecoration({
content: i+1,
margin: new soso.maps.Size(0, -4),
align: soso.maps.ALIGN.CENTER,
marker: marker
});
markers.push(marker);
}
map.fitBounds(latlngBounds);
} else {
$("#iCenter").append("检索没有结果,原因: " + status);
}
});
}
var showmap = function()
{
init();
searchKeyword();
}