标签:android 百度地图 定位 获取周边热点 申请key
百度地图申请keypublic void initdingwei(){ // 定位初始化 myListener = new MyLocationListenner(); mLocClient = new LocationClient(this); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true);// 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 option.setScanSpan(2000); // 设置扫描间隔,单位是毫秒 option.setIsNeedAddress(true);// 设置是否需要地址信息,默认为无地址 mLocClient.setLocOption(option); mLocClient.start(); }
/** * 定位SDK监听函数 */ public class MyLocationListenner implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { if (location == null) return; Log.i(TAG, "SDK监听函数11-->" + location.getLatitude() + " " + location.getLongitude() + " " + location.getCity()); } public void onReceivePoi(BDLocation poiLocation) { } }
/** * 查询周边 * http://api.map.baidu.com/place/v2/search * ak=您的密钥& * output=json& * query=%E9%93%B6%E8%A1%8C& * page_size=10& * page_num=0& * scope=1& * location=39.915,116.404& * radius=2000 */ public void getdata() { HttpUtils http = new HttpUtils(); RequestParams params = new RequestParams(); try { params.addBodyParameter("query", URLEncoder.encode("银行", "UTF-8")); // params.addBodyParameter("location", URLEncoder.encode("29", "UTF-8")+"."+URLEncoder.encode("531831", "UTF-8")+","+URLEncoder.encode("106", "UTF-8")+"."+URLEncoder.encode("531831", "UTF-8"));//"29.531831,106.576501"); params.addBodyParameter("radius", "2000"); params.addBodyParameter("output", "json"); params.addBodyParameter("ak", "VRMNc7QoiSM5ar5at5g3lRQD"); params.addBodyParameter("scope", "1"); params.addBodyParameter("page_size", "10"); params.addBodyParameter("page_num", "0"); params.addBodyParameter("mcode", "DA:4C:B6:A9:55:62:1D:AD:12:29:DD:7B:69:31:67:47:C5:B2:4E:E1;szj.com.ditu"); http.send(HttpRequest.HttpMethod.POST, // "http://api.map.baidu.com/place/v2/search?ak=VRMNc7QoiSM5ar5at5g3lRQD&output=json&query=%E9%93%B6%E8%A1%8C&page_size=10&page_num=0&scope=1&location=29.531831,106.576501&radius=2000&mcode==DA:4C:B6:A9:55:62:1D:AD:12:29:DD:7B:69:31:67:47:C5:B2:4E:E1;szj.com.ditu", "http://api.map.baidu.com/place/v2/search?ak=VRMNc7QoiSM5ar5at5g3lRQD&output=json&query=" + URLEncoder.encode("餐馆", "UTF-8")+URLEncoder.encode("$", "UTF-8")+URLEncoder.encode("银行", "UTF-8") + "&page_size=20&page_num=0&scope=1&location="+URLEncoder.encode(latitude, "UTF-8")+","+URLEncoder.encode(longitude, "UTF-8")+"&radius=2000&mcode==DA:4C:B6:A9:55:62:1D:AD:12:29:DD:7B:69:31:67:47:C5:B2:4E:E1;szj.com.ditu", params, new RequestCallBack<String>() { @Override public void onStart() { } @Override public void onLoading(long total, long current, boolean isUploading) { } @Override public void onSuccess(ResponseInfo<String> responseInfo) { String Data = responseInfo.result.toString(); try { JSONObject jsonObject = new JSONObject(Data.toString()); if (jsonObject.getInt("status") == 0 && "ok".equals(jsonObject.getString("message"))) { JSONArray jsonArray = jsonObject.getJSONArray("results"); ArrayList<Address> data; Gson gson = new Gson(); Type type = new TypeToken<ArrayList<Address>>() { }.getType(); data = gson.fromJson(jsonArray.toString(), type); adapter.setData(data); adapter.notifyDataSetChanged(); } } catch (Exception e) { } } @Override public void onFailure(HttpException error, String msg) { Toast.makeText(context, "连接服务器失败,请检查网络后重试~", Toast.LENGTH_SHORT).show(); } }); } catch (Exception e) { } }
标签:android 百度地图 定位 获取周边热点 申请key
原文地址:http://blog.csdn.net/biickvtkd/article/details/45580043