高德地图:显示地点,点击地点在地图上显示详情

效果图

在这里插入图片描述

高德API示例

示例地址

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>关键字检索</title>
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
    <style type="text/css">
        #panel {
            position: absolute;
            background-color: white;
            max-height: 90%;
            overflow-y: auto;
            top: 10px;
            right: 10px;
            width: 280px;
        }
    </style>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
</head>
<body>
<div id="container"></div>
<div id="panel"></div>
<script type="text/javascript">
    var map = new AMap.Map("container", {
        resizeEnable: true
    });
    AMap.service(["AMap.PlaceSearch"], function() {
        //构造地点查询类
        var placeSearch = new AMap.PlaceSearch({ 
            pageSize: 6, // 单页显示结果条数
            pageIndex: 1, // 页码
            citylimit: true,  //是否强制限制在设置的城市内搜索
            map: map, // 展现结果的地图实例
            panel: "panel", // 结果列表将在此容器中进行展示。
            autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
        });
        //关键字查询
        placeSearch.search('廊坊师范学院')
    });
</script>
</body>
</html>

关键代码解析

在这里插入图片描述

2.自己实现

如果高德的搜索内容里,没有自己想要的数据,可以结合高德地图,实现相同的功能。

<body >
<div>
 	<p class="contentTitle">社区信息</p>
 	<p th:each="list:${list}" th:text="${list.communityname}" th:onclick="communityInfo([[${list.communityId}]])")></p>
</div>
<script>
 function communityInfo(communityId){
 		//清除地图上其他标注
        map.clearMap();
        $.ajax({
            type: 'get',
            dataType: 'text',
            url:  '/mapImage/queryCommunityInfoById/'+communityId,
            p: [],
            cache: false,
            async: true,
            success: function (p) {
                var p = eval('(' + p + ')');
                for (var i = 0; i < p.rows.length; i++) {
                    var point=[p.rows[i].longitude,p.rows[i].latitude];
                    var marker = new AMap.Marker({
                        position: point,
                        map: map,
                        icon: new AMap.Icon({
                            image: "/img/marker/community.png",
                            imageSize: new AMap.Size(33,35)
                        })
                    });
                    
                    //显示marker
                    unitMarker.push(marker);
                    marker.communityname = p.rows[i].communityname;
                    
                    //点击marker显示信息框
                    marker.on('click', function(p){
                        var content = '<ul style="font-size:15px;">' +
                            '<strong style="color: rgb(24, 166, 137);text-align:left">社区信息</strong>'
                            + '<ul> 社区名称:'+p.target.communityname+'</ul>';
                        // 设置信息框内容
                        infoWindow.setContent(content);

                        //将marker放到指定坐标
                        infoWindow.open(map, p.lnglat);
                    });
                }
            }
        });
    }
</script>

关键代码解析

在这里插入图片描述

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值