通过高德api查询所有店铺地址信息

需求:通过高德api查询所有店铺地址信息

需求分析

查询现有高德api发现现有接口关键字搜索API服务地址:

https://developer.amap.com/api/webservice/guide/api/search
参数需要主要参数:key、types、city
其中types city可以查询:
https://developer.amap.com/api/webservice/download

具体实现

1、申请高德appkey

地址:https://console.amap.com/dev/key/app

2、下载types city 字典值

并将字典值解析读取到代码中,如图
在这里插入图片描述

3、具体代码调用

类说明:

Api  调用方法
CityUtil 城市编码查询工具类
ReaderFile 文件读写工具类
Shop 地点实体类
ShopUtil 地点查询工具类

具体代码

package com.gaode;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间:2024/6/21
 * 描述:
 */

public class Api {
    /**
     * 需要设置自己的apikey
     */
    public static String apiKey = "";
    public static void main(String[] args)  throws Exception{
        //查询单个城市
        List<Shop> AllShopList = new ArrayList<>();
        List<String> types = ReaderFile.getTypes();
        List<String> citys = ReaderFile.getCitys();
        for (int i = 0; i < types.size(); i++) {
            String type = types.get(i);
            for (int j = 0; j < citys.size(); j++) {
                String city = citys.get(i);
                List<Shop> shopList = ShopUtil.queryShops(city,type);
                if(CollectionUtil.isNotEmpty(shopList)){
                    AllShopList.addAll(shopList);
                }
                if(CollectionUtil.isNotEmpty(AllShopList)){
                    System.out.println(shopList.size());
                    System.out.println(shopList);
                    continue;
                }
            }
        }
        System.out.println("结束===================");
        System.out.println("=============="+AllShopList.size());
        System.out.println(JSON.toJSONString(AllShopList));

    }


    public static  List<Shop> queryAll() {
        List<Shop> shopList = new ArrayList<>();
        List<String> list = CityUtil.queryCitys();
        if (CollectionUtil.isNotEmpty(list)) {
            for (String city : list) {
                List<Shop> oneShopList = ShopUtil.queryShops(city,null);
                if (CollectionUtil.isNotEmpty(oneShopList)) {
                    shopList.addAll(oneShopList);
                }
            }
        }
        return shopList;
    }
}
package com.gaode;

/**
 * 描述:
 */

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;


public class CityUtil {
    public static List<String> queryCitys(){
        String apiKey  = Api.apiKey;
        List<String> ls = new ArrayList<>();
        // 获取所有城市列表
        String cityListUrl = "https://restapi.amap.com/v3/config/district?key=" + apiKey + "&subdistrict=1";
        String cityListResponse = null;
        try {
            cityListResponse = sendGetRequest(cityListUrl);
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心系代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值