从数据库获取到的多个点(有具体的经纬度),显示在百度地图上

14 篇文章 0 订阅

数据库结构:long是经度,lat是纬度。。这张表示行程点数据表。。

这张表是行程设定表。。。

控制器代码:

public function map(){

//查询一篇文章每一天的行程点
$trip1 = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->order('days asc')->where(array('zxid'=>$_GET['zxid'],'days'=>1))->select();
$trip2 = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->order('days asc')->where(array('zxid'=>$_GET['zxid'],'days'=>2))->select();
$trip3 = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->order('days asc')->where(array('zxid'=>$_GET['zxid'],'days'=>3))->select();
$trip4 = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->order('days asc')->where(array('zxid'=>$_GET['zxid'],'days'=>4))->select();
$trip5 = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->order('days asc')->where(array('zxid'=>$_GET['zxid'],'days'=>5))->select();
$trip6 = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->order('days asc')->where(array('zxid'=>$_GET['zxid'],'days'=>6))->select();
$trip7 = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->order('days asc')->where(array('zxid'=>$_GET['zxid'],'days'=>7))->select();

//分配 到视图
$this->assign("trip1",$trip1);
$this->assign("trip2",$trip2);
$this->assign("trip3",$trip3);
$this->assign("trip4",$trip4);
$this->assign("trip5",$trip5);
$this->assign("trip6",$trip6);
$this->assign("trip7",$trip7);
$this->display();
}
public function map_list(){
$map_list = M('Ltinerary_setting')->join('LEFT JOIN pigcms_system_trip on pigcms_system_trip.id = pigcms_ltinerary_setting.xcdid')->field('title,long,lat')->where(array('zxid'=>$_GET['zxid'],'days'=>$_GET['days']))->select();
$nlist = array();
foreach ($map_list as $k => &$v) {
//$v['long'] = $v['long'].",".$v['lat'];
$nlist[$k]['title']=$v['title'];
$nlist[$k]['point']= $v['long'].",".$v['lat'];//改变数组的键名称,值把经纬度拼接在一起,用逗号隔开
}
$this->assign('str',$str);
$this->display();
}

视图代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">



<meta name="viewport" content="initial-scale=1.0, user-scalable=no, target-densitydpi=device-dpi" />




    <title>百度地图API显示多个标注点带提示的代码</title>
    <!--css-->
<style>
body { margin: 0; font-family: "Helvetica,Arial,FreeSans"; color: #000000; font-size: 12px; }
.demo_main { padding: 20px; padding-top: 10px; }
.demo_title { padding: 10px; margin-bottom: 10px; background-color: #D3D8E0; border: solid 1px gray; }
.demo_content { padding: 10px; margin-bottom: 10px; border: solid 1px gray; }
fieldset { border: 1px solid gray; }
</style>
    <link href="style/demo.css" rel="stylesheet" type="text/css" />
    <!--javascript-->
    <script src="scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="scripts/demo.js" type="text/javascript"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.0/jquery.js"></script>
</head>
<body>
    <div class="demo_main">
        <fieldset class="demo_content">
            <div style="min-height: 1000px; width: 100%;" id="map">
            </div>
            <script type="text/javascript">
               // var markerArr1 = {pigcms{$map_list};
//alert(markerArr1);


//for(var i=0;i<markerArr1.length;i++){
//alert(markerArr1[i]['title']);
//alert(markerArr1[i]['long']);
  // markerArr = [{ title: markerArr1[i]['title'], point: markerArr1[i]['long']}];
//alert(markerArr);
//}

var str = '{pigcms{$str}';
//alert(str);
var markerArr = $.parseJSON(str);
//alert(markerArr);
//alert(str);
//var markerArr = {pigcms{$str};

//alert({pigcms{$str});
//var str = '{pigcms{$map_list}';

//var markerArr = JSON.parse(str); 




//alert(eval(str));

/*var markerArr = 
[
                    { title: "名称:广州火车站", point: "116.3964,39.9093"},
                    { title: "名称:广州塔(赤岗塔)", point: "113.330934,23.113401", address: "广东省广州市广州塔(赤岗塔) ", tel: "18500000000" },
                    { title: "名称:广州动物园", point: "113.312213,23.147267", address: "广东省广州市广州动物园", tel: "18500000000" },
                    { title: "名称:天河公园", point: "113.372867,23.134274", address: "广东省广州市天河公园", tel: "18500000000" }
];  
alert(typeof(markerArr));
*/
                function map_init() {
                    var map = new BMap.Map("map"); // 创建Map实例
                    var point = new BMap.Point(120.25491, 30.20008); //地图中心点,广州市
                    map.centerAndZoom(point, 12); // 初始化地图,设置中心点坐标和地图级别。
                    map.enableScrollWheelZoom(true); //启用滚轮放大缩小
                    //向地图中添加缩放控件
                    var ctrlNav = new window.BMap.NavigationControl({
                        anchor: BMAP_ANCHOR_TOP_LEFT,
                        type: BMAP_NAVIGATION_CONTROL_LARGE
                    });
                    map.addControl(ctrlNav);


                    //向地图中添加缩略图控件
                    var ctrlOve = new window.BMap.OverviewMapControl({
                        anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
                        isOpen: 1
                    });
                    map.addControl(ctrlOve);


                    //向地图中添加比例尺控件
                    var ctrlSca = new window.BMap.ScaleControl({
                        anchor: BMAP_ANCHOR_BOTTOM_LEFT
                    });
                    map.addControl(ctrlSca);


                    var point = new Array(); //存放标注点经纬信息的数组
                    var marker = new Array(); //存放标注点对象的数组
                    var info = new Array(); //存放提示信息窗口对象的数组
                    for (var i = 0; i < markerArr.length; i++) {
                        var p0 = markerArr[i].point.split(",")[0]; //
                        var p1 = markerArr[i].point.split(",")[1]; //按照原数组的point格式将地图点坐标的经纬度分别提出来
                        point[i] = new window.BMap.Point(p0, p1); //循环生成新的地图点
                        marker[i] = new window.BMap.Marker(point[i]); //按照地图点坐标生成标记
                        map.addOverlay(marker[i]);
                        marker[i].setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
                        var label = new window.BMap.Label(markerArr[i].title, { offset: new window.BMap.Size(20, -10) });
                        marker[i].setLabel(label);
                        //info[i] = new window.BMap.InfoWindow("<p style=’font-size:12px;lineheight:1.8em;’>" + markerArr[i].title + "</br>地址:" + markerArr[i].address + "</br> 电话:" + markerArr[i].tel + "</br></p>"); // 创建信息窗口对象
                    }
                    marker[0].addEventListener("mouseover", function () {
                        this.openInfoWindow(info[0]);
                    });
                    marker[1].addEventListener("mouseover", function () {
                        this.openInfoWindow(info[1]);
                    });
                    marker[2].addEventListener("mouseover", function () {
                        this.openInfoWindow(info[2]);
                    });
                }
                //异步调用百度js
                function map_load() {
                    var load = document.createElement("script");
                    load.src = "http://api.map.baidu.com/api?v=1.4&callback=map_init";
                    document.body.appendChild(load);
                }
                window.onload = map_load;
            </script>
        </fieldset>
    </div>
<select>
<volist name="map_list" id="vo">
<option>{pigcms{$vo.long},{pigcms{$vo.lat}</option>
</volist>
</select>
</body>
</html>

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值