//请求用户微博信息 function request(user_id){ createXMLHttpRequest(); xmlHttp.onreadystatechange = back; var str = getUrl(); var url = str + "/points_handle.php?uid=" + user_id; xmlHttp.open("GET",url,true); xmlHttp.send(null); } //得到微博信息 function back() { if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200) { //status状态正常时 var response = xmlHttp.responseText; var obj = eval('('+response+')'); //将json数据转换为对象(object)形式 //alert(response); if( obj.data != null ){ for(var i = 0; i < obj.data.length; i++) { (function(x){ //alert(obj.data[i].point[1]); var pt = new BMap.Point(obj.data[i].point[1],obj.data[i].point[0]); var marker = new BMap.Marker(pt); var text = obj.data[i].text; var length = text.length; //alert(text.length); var opt = { 300, height:length + 50, title:'<span style="font-size:15px;color:red">' + obj.uid + '</span>' } map.addOverlay(marker); marker.setAnimation(BMAP_ANIMATION_BOUNCE); marker.addEventListener("click",function(){ openInfo(text,marker,opt); }); })(i); } //map.addControl(new BMap.NavigationControl()); }else{ alert("数据库中没有该ID"); } } } } function openInfo(text,marker,opt){ var p = marker.getPosition(); var point = new BMap.Point(p.lng,p.lat); var infoWindow = new BMap.InfoWindow(text,opt); map.openInfoWindow(infoWindow,point); }