1、利用位置得到经纬度:
String url="http://api.map.baidu.com/geocoder/v2/?address=" +place1+
"&ak=cev92xxxxxxxxx4HibK&callback=showLocation&" +
"output=json&pois=0&mcode=" + "9F:F9:BF:E5:B1:FF:71:2C:xxxxxxxxxxxxxxxxxxx;com.xxxxxxx.xxxxxxxx";
利用get网络请求这个url;
其中 place1:地址;
ak:开发者平台的应用ak;
mcode:安全码;
最后是包名;
成功返回:
showLocation&&showLocation({"status":0,"result":{"location":{"lng":120.1609994741205,"lat":30.26998128653152},"precise":1,"confidence":80,"level":"道路"}})
解析得到 经纬度。
解析这个就很纳闷 我只想到了
String str2=str.replace("showLocation&&showLocation(","");
String str3=str2.replace(")","");
然后后面就JSONObject 了。好low啊 没想到更好的办法了。。。
2、传经纬度 得到位置
String url3="http://api.map.baidu.com/geocoder/v2/?ak=xxxxxxxxxxxxxxxxxxxxx&callback=renderReverse&location=39.983424,116.322987&output=json&pois=1&mcode=" +
"9F:F9:BF:E5:B1:FF:71:2C:ED:5B:6Axxxxxxxxxxxxxxxxx;com.xxxxxx.xxxxxx";
替换了
callback=showLocation —->callback=renderReverse
address=位置—->location =经纬度
返回值的格式也差不多
具体看:http://api.map.baidu.com/lbsapi/cloud/webservice-geocoding.htm
参考:
http://blog.youkuaiyun.com/zfs2008zfs/article/details/52819274
http://blog.youkuaiyun.com/zhangli_/article/details/50115997