调用百度LBS云地理编码解析(spring boot)

调用百度LBS云地理编码解析(spring boot)

//1 创建浏览器HttpClient对象
        CloseableHttpClient client = HttpClients.createDefault();
        //2 创建请求方式
        //geotable_id :服务器上的   :存储自定义数据时生成的数据表ID
        //address:必须
        //city:城市名
        //ak:必须
        String url = "http://api.map.baidu.com/cloudgc/v1?address=沭阳县传智专修学院&ak=你的ak"; 
        HttpGet get = new HttpGet(url);
        //3 请求+接受响应结果
        CloseableHttpResponse response = client.execute(get);
        //4 解析结果
        int code = response.getStatusLine().getStatusCode();
        System.out.println(code);

        HttpEntity entity = response.getEntity();
        //如果直接打印entity,打印的是内存地址;所以需要通过EntityUtils.toString方法,将对象中的属性的值转成json类型
        System.out.println(EntityUtils.toString(entity));

        //5 关闭资源
        response.close();
        client.close();

点击这里查看LBS.云服务API

猜你喜欢

转载自blog.csdn.net/weixin_42633131/article/details/82797855