This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
LH-hanpijunbuhanpi LH 初始化项目 c69c526 10 months ago
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README

Amap Web SDK

介绍

本项目集成高德的Web服务Api。

使用

public class Sample {
    public static void main(String[] args) {
        // 1. 初始化服务
        DefaultAmapConfig config = new DefaultAmapConfig("高德Web服务Key"); // 创建高德配置
        AmapHttpClient client = new AmapHttpClient(); // 创建http客户端
        AmapWebService service = new AmapWebService(config, client); // 创建服务对象

        // 2. 获取不同请求形式的服务对象
        AmapWebExecuteService es = service.execute(); // 直接请求形式,会将请求原原本本的返回
        AmapWebThrowService ts = service.thrower(); // 抛错形式,如果请求失败/异常/不成功,将会抛出异常
        AmapWebAsyncService as = service.async(); // 异步形式,会异步调用api

        // 3. 各形式服务演示(以地理编码api为例)
        GeocodeCommand geocodeCommand = new GeocodeCommand("北京市朝阳区阜通东大街6号");
        // 3.1 直接请求形式
        GeocodeResult geocodeResult = es.geocode(geocodeCommand);
        if (!geocodeResult.isSuccessful()) {
            throw new RuntimeException("请求失败: info=" + geocodeResult.getInfo() + ", infocode=" + geocodeResult.getInfocode());
        }
        System.out.println(geocodeResult.getGeocodes());
        // 3.2 抛错形式
        List<Geocode> geocodes = ts.geocode(geocodeCommand);
        System.out.println(geocodes);
        // 3.3 异步形式
        as.geocode(geocodeCommand, new AmapCallback<GeocodeResult>()
                .success(((call, response) -> {
                    System.out.println("请求成功");
                    GeocodeResult result = response.body();
                    // 其他操作 ...
                }))
                .fail(((call, throwable) -> {
                    System.out.println("请求失败");
                    throwable.printStackTrace();
                })));
    }
}

Empty file

About

Cancel

Releases

No release

Contributors

All

Activities

can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化