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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值