<?php
$dbhost = ‘localhost‘;
$dbuser = ‘xcy_dzsw‘; //我的用户名
$dbpass = ‘xcy_dzsw‘; //我的密码
$dbname = ‘xcy_dzsw‘; //我的mysql库名
$connect = mysql_connect($dbhost,$dbuser,$dbpass,$dbname);
/*
if ($connect) {
echo "非常好,成功了!";
} else {
echo "不好意思,失败了!";
}
*/
mysql_query("SET CHARACTER SET UTF8");//转码utf-8
mysql_select_db("xcy_dzsw", $connect);
$result = mysql_query("SELECT * FROM joy_user_detail");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="keywords" content="天地图"/>
<title>电子商务乡村游</title>
<script type="text/javascript" src="http://api.tianditu.com/js/maps.js"></script>
<script>
var map;
var zoom =11;
function onLoad()
{
//初始化地图对象
map=new TMap("mapDiv");
//设置显示地图的中心点和级别
map.centerAndZoom(new TLngLat(114.3162425771,30.3779623154),zoom);
//允许鼠标滚轮缩放地图
map.enableHandleMouseScroll();
//var marker = new TMarker(new TLngLat(114.4124903640,30.3492432973));
//map.addOverLay(marker);
//循环读点,并放进地图里
<?php
$i=0;
while($row = mysql_fetch_array($result)){
$i++;
$address = $row[‘map_zb‘];
$jingdu = strtok ( $address, ‘,‘ );
$weidu = ltrim(strstr ( $address, ‘,‘ ), ",");
echo "var marker".$i." = new TMarker(new TLngLat(".$jingdu.",".$weidu."));map.addOverLay(marker".$i.");";
echo "var config".$i." = {text:\"<a href=‘http://xcy.365960.com/house.php?id=".$row[‘id‘]."&str=njl‘ target=‘_blank‘>".$row[‘subname‘]."</a>\",offset:new TPixel(0,0),position:new TLngLat(".$jingdu.",".$weidu.")};var label".$i."=new TLabel(config".$i."); map.addOverLay(label".$i."); ";
}
?>
}
</script>
</head>
<body onLoad="onLoad()">
<div id="mapDiv" style="position:absolute;width:100%; height:500px"></div>
</body>
</html>