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

android 百度查询当前所在省市區 百度地图定位 并获取当前省市区Id

时间:2023-03-22 08:19:25

相关推荐

android 百度查询当前所在省市區 百度地图定位 并获取当前省市区Id

//获取地里位置 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/", //根据城市名称,查询城市Id

data: { proName: province, cityName: city, areaName: area },

success: function (data) {

if (data.status) {

//console.log(data)

//绑定省市区定位城市

html = '

' + province + '\'+ city + '\'+ area + '';

$("#PCALi").html(html);

} else {

layer.open({ content: "正在获取GPS信息", time: 2 });

}

}

});

});

}

else {

layer.open({ content: "定位失败,请重试!", time: 2 });

}

}, { enableHighAccuracy: true });

});

//获取地里位置 End

#region 根据所属城市查询城市ID

/// 根据所属城市查询城市ID

///

///

///

[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))

{

//根据城市获取地区id

var 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; //返回当前城市Id

var resultObj = JsonConvert.SerializeObject(obj);

HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json") };

return result;

}

#endregion

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