ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 百度定位模块 > 引入第三方模块 **baiduLocation** ![](https://box.kancloud.cn/bd4190ec98927dd7855b43d958ade0b7_508x100.png) 配置**apikey**, **ios** 和 **安卓**的AK均可 需要引入**init.js** 、**app.js** 、**api.js** ~~~ baiduLocation = api.require('baiduLocation'); baiduLocation.startLocation({ accuracy: '100m', filter: 1, autoStop: true }, function(ret, err) { if (ret.status) { location2address(ret.latitude,ret.longitude); } else { alert(JSON.stringify(err)); } }); function location2address(lat,lon) { var baidu_url="http://api.map.baidu.com/geocoder/v2/";//百度服务端接口地址 var data = "{values :{ak:'eUdorifLUUXVV9FMINfsTbTx',location:'"+lat+","+lon+"',output:'json',pois:'0'}}"; r_ajax(baidu_url,data,function(ret) { // alert($api.jsonToStr(ret)); cityName = ret.result.addressComponent.city; // 城市名称 cityName = cityName.replace("\"","").replace("\"",""); //正则去掉双引号 cityName = cityName.substring(0,cityName.length-1); //去掉最后一个市字 // alert(cityName); $api.html($api.byId('cityname'),cityName); }); } ~~~