300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 百度地图定位 并获取当前省市区Id

百度地图定位 并获取当前省市区Id

时间:2019-10-30 23:44:54

相关推荐

百度地图定位 并获取当前省市区Id

<!-- 百度地图 --><script type="text/javascript" src="http://api./api?v=2.0&ak=FbzOyQ4YujPrZsxiQKoB07aB"></script> <script>//获取地里位置 Start$(function () { $("#demo1").val("正在获取您的位置...");var geolocation = new BMap.Geolocation();var gc = new BMap.Geocoder();geolocation.getCurrentPosition(function (r) {if (this.getStatus() == BMAP_STATUS_SUCCESS) {//appLat = r.point.lat;//appLng = r.point.lng;var pt = r.point;gc.getLocation(pt, function (rs) {var addComp = rs.addressComponents;var province = addComp.province;var city = addComp.city;var area = addComp.district;if (province != "" && city != "" && area != "") {$("#demo1").val(province + " " + city + " " + area);}$.ajax({type: 'POST',url: "http://localhost:11111/api/BDCheckCity/", //根据城市名称,查询城市Iddata: { proName: province, cityName: city, areaName: area },success: function (data) {if (data.status) {//console.log(data)//绑定省市区定位城市html = '<li><span>' + province + '</span><i class="fa fa-angle-up" aria-hidden="true"></i></li>\<li><span>'+ city + '</span><i class="fa fa-angle-up" aria-hidden="true"></i></li>\<li><span>'+ area + '</span><i class="fa fa-angle-up" aria-hidden="true"></i></li>';$("#PCALi").html(html);} else {layer.open({ content: "正在获取GPS信息", time: 2 });}}});});}else {layer.open({ content: "定位失败,请重试!", time: 2 });}}, { enableHighAccuracy: true });});//获取地里位置 End</script>

#region 根据所属城市查询城市ID/// <summary>根据所属城市查询城市ID/// </summary>/// <param name="cityName"></param>/// <returns></returns>[Route("api/BDCheckCity/")][HttpPost]public HttpResponseMessage BDCheckCity(){var proName = MSCL.RequestHelper.GetString("proName");var cityName = MSCL.RequestHelper.GetString("cityName");var areaName = MSCL.RequestHelper.GetString("areaName");ReturnData rd = new ReturnData();string pId = "0", cId = "0", aId = "0";Core.Model.Areas areasEntity = null;if (!string.IsNullOrEmpty(proName)){//根据城市获取地区idvar pEntity = Core.Bll.Areas.GetAll().Where(e => e.Name == proName);if (pEntity != null && pEntity.Count() > 0){areasEntity = pEntity.FirstOrDefault();}pId = areasEntity.Id.ToString();}if (!string.IsNullOrEmpty(cityName)){var cEntity = JianKu.Core.Bll.Areas.GetAll().Where(e => e.Name == cityName);if (cEntity != null && cEntity.Count() > 0){areasEntity = cEntity.FirstOrDefault();}cId = areasEntity.Id.ToString();}else{rd.Status = 3;rd.Msg = "正在获取GPS信息";}if (!string.IsNullOrEmpty(areaName)){var aEntity = Core.Bll.Areas.GetAll().Where(e => e.Name == areaName);if (aEntity != null && aEntity.Count() > 0){areasEntity = aEntity.FirstOrDefault();}aId = areasEntity.Id.ToString();}ResponseResult obj = new ResponseResult();obj.status = true;obj.message = pId + "," + cId + "," + aId; //返回当前城市Idvar resultObj = JsonConvert.SerializeObject(obj);HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json") };return result;}#endregion

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。