濮阳杆衣贸易有限公司

主頁 > 知識庫 > 使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能

使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能

熱門標(biāo)簽:機(jī)器人外呼系統(tǒng)軟件存在問題 沈陽營銷電銷機(jī)器人招商 福州電銷機(jī)器人源代碼 南京400電話怎樣辦理 企業(yè)智能外呼系統(tǒng)價格多少 智能電銷機(jī)器人銷售話術(shù) 高德地圖標(biāo)注商戶位置 徐州ai電銷機(jī)器人原理 兗州電話外呼營銷系統(tǒng)

1.首先拿到百度地圖開發(fā)密鑰,進(jìn)入百度地圖開放平臺:百度地圖開放平臺

(1)選擇開發(fā)文檔>>web開發(fā)>>JavaScript API

(2)需要申請密鑰才可使用,點(diǎn)擊申請密鑰(申請密鑰的IP白名單可以用‘ * '代替,所有網(wǎng)站都可用,但安全性很差,所有人都可以抓到這個ak來使用,也可以根據(jù)自己的應(yīng)用場景來設(shè)置) 

 2,Controller代碼

public class MapController : Controller
    {
        //map視圖
        public ActionResult Index()
        {
            return View();
        }
        /// summary>
        /// 存入坐標(biāo)點(diǎn)
        /// /summary>
        /// param name="Longitude">經(jīng)度/param>
        /// param name="Latitude">緯度/param>
        /// param name="Name">名稱/param>
        /// returns>/returns>
        public ActionResult Set(string Longitude, string Latitude, string Name)
        {
            //初始化redis
            CSRedis.CSRedisClient cSRedis = new CSRedis.CSRedisClient("192.168.56.131:6380,password=123456,defaultDatabase = 0");
            RedisHelper.Initialization(cSRedis);
 
            decimal Lng = decimal.Parse(Longitude);
            decimal Lat = decimal.Parse(Latitude);
            //存入坐標(biāo)點(diǎn)
            var flag = RedisHelper.GeoAdd("zhongguo", Lng, Lat, Name);
 
            if (flag == true)
            {
                return Json(new { code = 1, message = "成功" });
            }
            else
            {
                return Json(new { code = 0, message = "提交失敗" });
            }
        }
        /// summary>
        /// 獲取半徑范圍內(nèi)的其他坐標(biāo)
        /// /summary>
        /// param name="lng">經(jīng)度/param>
        /// param name="lat">緯度/param>
        /// param name="ran">半徑/param>
        /// returns>/returns>
        public ActionResult Get(string lng, string lat, string ran)
        {
            //初始化redis
            CSRedis.CSRedisClient cSRedis = new CSRedis.CSRedisClient("192.168.56.131:6380,password=123456,defaultDatabase = 0");
            RedisHelper.Initialization(cSRedis);
 
            decimal Lng = decimal.Parse(lng);
            decimal Lat = decimal.Parse(lat);
            decimal Ran = decimal.Parse(ran);
            var K = CSRedis.GeoUnit.km;
            //獲取周邊坐標(biāo)點(diǎn)
            (string member, decimal dist, decimal longitude, decimal latitude)[] list_ = RedisHelper.GeoRadiusWithDistAndCoord("zhongguo", Lng, Lat, Ran, K);
            return Json(list_, JsonRequestBehavior.AllowGet);
        }
    }

3,view代碼(注意填寫上面申請的密鑰)

@{
    Layout = null;
}
!DOCTYPE html>
html lang="zh-CN">
head>
    meta charset="utf-8">
    title>地圖展示/title>
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    meta http-equiv="X-UA-Compatible" content="IE=Edge">
    style>
        body,
        html,
        #container {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微軟雅黑";
        }
 
        .info {
            z-index: 999;
            width: auto;
            min-width: 22rem;
            padding: .75rem 1.25rem;
            margin-left: 1.25rem;
            position: fixed;
            top: 1rem;
            background-color: #fff;
            border-radius: .25rem;
            font-size: 14px;
            color: #666;
            box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
        }
    /style>
    link href="~/Content/button.css" rel="external nofollow"  rel="stylesheet" />
    script src="http://api.map.baidu.com/api?type=webglv=1.0ak=你的密鑰">/script>
    script src="~/Scripts/jquery-3.4.1.min.js">/script>
    script>
        function bing() {
        var lng = $("#lng").val();
        var lat = $("#lat").val();
        var ran = $("#ran").val();
 
        $.ajax({
            url: "@Url.Action("Get", "Map")",
            data: {
                lng: lng,
                lat: lat,
                ran:ran
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                console.log(data)
 
                if (data != null) {
                    for (var i = 0; i  data.length; i++) {
                        var new_point = new BMapGL.Point(data[i]['Item3'], data[i]['Item4']);
                        console.log(data[i]['Item3'])
                        console.log(data[i]['Item4'])
                        var marker = new BMapGL.Marker(new_point);  // 創(chuàng)建標(biāo)注
                        map.addOverlay(marker);              // 將標(biāo)注添加到地圖中
                        map.panTo(new_point);
                    }
                }
            }
        });
        }
    /script>
/head>
body>
    div id="container">/div>
    input type="text" id="ti" name="name" value="" placeholder="請輸入名稱" class="info" />
    div id="re">
        經(jīng)度:
        input type="text" id="lng" name="name" value="" />
        緯度:
        input type="text" id="lat" name="name" value="" />
        范圍:
        input type="text" id="ran" name="name" value="" />
        button id="reu" name="name" onclick="bing()" value="查詢">查詢/button>
    /div>
    input type="hidden" name="GetLng" value="" />
    div id="allmap">/div>
/body>
/html>
script>
    var map = new BMapGL.Map('container'); // 創(chuàng)建Map實(shí)例
    map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 12); // 初始化地圖,設(shè)置中心點(diǎn)坐標(biāo)和地圖級別
    map.enableScrollWheelZoom(true); // 開啟鼠標(biāo)滾輪縮放
/script>
script>
    var map = new BMapGL.Map('container');
    map.centerAndZoom(new BMapGL.Point(116.404, 39.928), 15);
    map.enableScrollWheelZoom(true);
    map.addEventListener('click', function (e) {
        alert( + e.latlng.lng + ',' + e.latlng.lat);
        if (confirm("是否添加此地址")) {
        var Longitude = e.latlng.lng;
        var Latitude = e.latlng.lat;
        var Name = $("#ti").val();
        $.ajax({
            url: "@Url.Action("Set", "Map")",
            data: {
                Longitude: Longitude,
                Latitude: Latitude,
                Name: Name
            },
            type: "post", 
            dataType: "json",
            success: function (data) {
                if (data.code) {
                    alert(data.message);
                }
                else {
                    alert(data.message);
                }
            }
        });
      }
    });
/script>
script type="text/javascript">
        // 百度地圖API功能
/script>

到此這篇關(guān)于使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能的文章就介紹到這了,更多相關(guān)百度地圖api地標(biāo)存儲范圍坐標(biāo)點(diǎn)查詢內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 詳解vue.js下引入百度地圖jsApi的兩種方法
  • python通過百度地圖API獲取某地址的經(jīng)緯度詳解
  • 基于百度地圖api清除指定覆蓋物(Overlay)的方法
  • Python爬蟲實(shí)例_利用百度地圖API批量獲取城市所有的POI點(diǎn)
  • 百度地圖API之百度地圖退拽標(biāo)記點(diǎn)獲取經(jīng)緯度的實(shí)現(xiàn)代碼

標(biāo)簽:邯鄲 景德鎮(zhèn) 大理 吉安 本溪 鶴崗 丹東 昭通

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能》,本文關(guān)鍵詞  使用,百度,地圖,api,通過,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能》相關(guān)的同類信息!
  • 本頁收集關(guān)于使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    尼木县| 乐陵市| 江安县| 鹤山市| 和政县| 丹棱县| 济源市| 石门县| 灵山县| 朔州市| 沂水县| 鄂托克旗| 手机| 秦安县| 双流县| 枣阳市| 伊通| 黎平县| 伽师县| 建德市| 泰州市| 平度市| 尉氏县| 蛟河市| 昭苏县| 绵竹市| 保山市| 景德镇市| 浮梁县| 大新县| 漳浦县| 大石桥市| 墨江| 西乌珠穆沁旗| 余姚市| 宜良县| 杨浦区| 尼玛县| 石楼县| 西乌珠穆沁旗| 上饶市|