每篇文章仅做为自己的备忘笔记,若有描述不清或不对的地方还请指明,感谢^_^

使用百度地图 进行逆地址解析

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";font-size:14px;}
        #allmap {width:100%;height:100%;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=这里填写百度key"></script>
    <title>逆地址解析</title>
</head>
<body>
<div id="allmap"></div>
<script type="text/javascript" >
    function map_click(lng,lat){
        var map = new BMap.Map("allmap");
        var point = new BMap.Point(lng,lat);
        // map.centerAndZoom(point,12);
        var geoc = new BMap.Geocoder();
        geoc.getLocation(point,function(rs){
            var addComp = rs.addressComponents;
            console.log(addComp);
            alert(addComp.province  + addComp.city  + addComp.district + addComp.street + addComp.streetNumber);
        });
    }
    map_click(116.38,39.90);
    //参数解析
    //@parameter1 lng 传入的经度
    //@parameter2 lat 传入的纬度

</script>
</body>
</html>

 

posted @ 2020-05-22 18:01  菜汤不甜  阅读(1241)  评论(0编辑  收藏  举报