var point = new BMap.Point(longitude,latitude); //longitude经度 /latitude维度
map.centerAndZoom(point,11);
map.enableScrollWheelZoom();//启动滚轮缩放
map.enableScrollWheelZoom();//启动滚轮缩放
var options = {
onSearchComplete: function(results){
if (local.getStatus() == BMAP_STATUS_SUCCESS){
// 判断状态是否正确
var s = [];
for (var i = 0; i < results.getCurrentNumPois(); i ++){
s.push(results.getPoi(i).title + "," + results.getPoi(i).address+ ", " + results.getPoi(i).phoneNumber); //获得的信息
addMarker(results.getPoi(i).point,i,results.getPoi(i).title,results.getPoi(i).address,results.getPoi(i).phoneNumber);
//添加标记物
}
}
},
};
var local = new BMap.LocalSearch(map, options);
local.search(enterprise.full_name); //搜索的名称
function addMarker(point, index,title,address,phoneNumber){
// 创建图标对象
var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {
offset: new BMap.Size(10, 25), // 指定定位位置
imageOffset: new BMap.Size(0, 0) // 设置图片偏移
});
var marker = new BMap.Marker(point, {icon: myIcon});
marker.addEventListener("click", function(){
var opts = {
width : 150, // 信息窗口宽度
height: 60, // 信息窗口高度
title : title, // 信息窗口标题
address:address,
phoneNumber:phoneNumber
}
var txt="<span style='font-size:12px;margin-top:10px;margin-bottom:10px;'>地址: "+address+"</span>"+"<br/>"+"<span style='font-size:12px;margin-top:20px;margin-bottom:10px;'>电话: "+phoneNumber+"</span>"; //点击定位坐标弹出框显示的文本
var infowindow = new BMap.InfoWindow(txt,{width:150,height:100,title:title,enableMessage:false});
map.openInfoWindow(infowindow,point);
});
map.addOverlay(marker);}