阿里、百度、腾讯三家的根据坐标查找地址

项目中用到的小方法,分享一下
根据经纬度获取当前位置,下面罗列了阿里、百度、腾讯三家的坐标反查,基本大同小异 以腾讯为例
public String findAddr(String longitude, String latitude) {
    //latitude 纬度 小    longitude 经度 大
    //阿里参数解释: 纬度,经度 type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)
    //阿里坐标反查
    //String urlString = "http://gc.ditu.aliyun.com/regeocoding?l=" + latitude + "," + longitude + "&type=100";
    //百度坐标反查
   //String urlString = "http://api.map.baidu.com/geocoder/v2/?location=" + latitude + "," + longitude + "&output=json&ak=pxoWG9wF3GkmImh4zqI5M9ho" + "&pois=0";
    //腾讯坐标反查
    String urlString =  "https://apis.map.qq.com/ws/geocoder/v1/?location=" + latitude + "," + longitude + "&get_poi=1&key=RTDBZ-VCBW4-CEEU4-X3IOT-4EUQ2-QIBR5";

    String res = "";
    try {
        URL url = new URL(urlString);
        java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("post");
        java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), "UTF-8"));
        String line;
        while ((line = in.readLine()) != null) {
            res += line + "\n";
        }
        in.close();
    } catch (Exception e) {
        System.out.println("error in wapaction,and e is " + e.getMessage());
    }
    JSONObject jsStr = JSONObject.parseObject(res);
    JSONObject str = JSONObject.parseObject(jsStr.get("result").toString());
    return str.get("address").toString();
}

返回结果如下,大家取自己想要的数据即可

{
    "status": 0,
    "message": "query ok",
    "request_id": "69747eb4-f861-11e8-a8be-6c0b84d75b0d",
    "result": {
        "location": {
            "lat": 37.43365,
            "lng": 118.67466
        },
        "address": "山东省东营市东营区府前大街77号",
        "formatted_addresses": {
            "recommend": "东营市政府",
            "rough": "东营市政府"
        },
        "address_component": {
            "nation": "中国",
            "province": "山东省",
            "city": "东营市",
            "district": "东营区",
            "street": "府前大街",
            "street_number": "府前大街77号"
        },
        "ad_info": {
            "nation_code": "156",
            "adcode": "370502",
            "city_code": "156370500",
            "name": "中国,山东省,东营市,东营区",
            "location": {
                "lat": 37.433651,
                "lng": 118.67466
            },
            "nation": "中国",
            "province": "山东省",
            "city": "东营市",
            "district": "东营区"
        },
        "address_reference": {
            "crossroad": {
                "id": "4965374",
                "title": "胶州路/府前大街(路口)",
                "location": {
                    "lat": 37.43301,
                    "lng": 118.669823
                },
                "_distance": 428,
                "_dir_desc": "东"
            },
            "town": {
                "id": "370502003",
                "title": "东城街道",
                "location": {
                    "lat": 37.433651,
                    "lng": 118.67466
                },
                "_distance": 0,
                "_dir_desc": "内"
            },
            "street_number": {
                "id": "18144220246262240968",
                "title": "府前大街77号",
                "location": {
                    "lat": 37.433651,
                    "lng": 118.67466
                },
                "_distance": 28.5,
                "_dir_desc": ""
            },
            "street": {
                "id": "840368564172484022",
                "title": "府前大街",
                "location": {
                    "lat": 37.433052,
                    "lng": 118.674667
                },
                "_distance": 60.9,
                "_dir_desc": "北"
            },
            "landmark_l2": {
                "id": "9572013387547394861",
                "title": "东营市政府",
                "location": {
                    "lat": 37.433811,
                    "lng": 118.674408
                },
                "_distance": 0,
                "_dir_desc": "内"
            }
        },
        "poi_count": 10,
        "pois": [
            {
                "id": "9572013387547394861",
                "title": "东营市政府",
                "address": "山东省东营市东营区府前大街77号",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.433811,
                    "lng": 118.674408
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 0,
                "_dir_desc": "内"
            },
            {
                "id": "3778727006938218374",
                "title": "新世纪广场",
                "address": "山东省东营市东营区府前大街92号",
                "category": "旅游景点:城市广场",
                "location": {
                    "lat": 37.431801,
                    "lng": 118.67469
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 87.5,
                "_dir_desc": "北"
            },
            {
                "id": "17839288141395836424",
                "title": "东营市纪检委",
                "address": "山东省东营市东营区府前大街77号",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.434299,
                    "lng": 118.674583
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 72.5,
                "_dir_desc": "南"
            },
            {
                "id": "8824438052850152047",
                "title": "东营市委",
                "address": "山东省东营市东营区府前大街77号",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.434299,
                    "lng": 118.674583
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 72.5,
                "_dir_desc": "南"
            },
            {
                "id": "17434387281981270799",
                "title": "东营市民族事务委员会",
                "address": "山东省东营市东营区府前大街77号",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.43396,
                    "lng": 118.674614
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 34.6,
                "_dir_desc": ""
            },
            {
                "id": "9313042909846047882",
                "title": "东营市法制办公室",
                "address": "山东省东营市东营区府前大街77号",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.43396,
                    "lng": 118.674614
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 34.6,
                "_dir_desc": ""
            },
            {
                "id": "15024919115594198679",
                "title": "东营市发改委",
                "address": "山东省东营市东营区府前大街77号市政府大楼",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.434299,
                    "lng": 118.674583
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 72.5,
                "_dir_desc": "南"
            },
            {
                "id": "9074832677240004076",
                "title": "东营市科技局",
                "address": "山东省东营市东营区府前大街77号",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.434299,
                    "lng": 118.674583
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 72.5,
                "_dir_desc": "南"
            },
            {
                "id": "2857899543463581441",
                "title": "东营市人社局",
                "address": "山东省东营市东营区府前大街77号",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.434299,
                    "lng": 118.674583
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 72.5,
                "_dir_desc": "南"
            },
            {
                "id": "6359637021302127621",
                "title": "东营市监察委员会",
                "address": "山东省东营市东营区",
                "category": "机构团体:政府机关",
                "location": {
                    "lat": 37.434299,
                    "lng": 118.674583
                },
                "ad_info": {
                    "adcode": "370502",
                    "province": "山东省",
                    "city": "东营市",
                    "district": "东营区"
                },
                "_distance": 72.5,
                "_dir_desc": "南"
            }
        ]
    }
}

 

Maven是一个项目管理工具,用于自动化软件项目的构建、报告和文档。如果你想要在Maven项目中配置使用腾讯云的镜像仓库,你需要做以下几个步骤: 1. **添加阿里云Maven仓库**:首先,在`pom.xml`文件中加入阿里云Maven中央仓库的地址,因为腾讯云并没有直接提供官方的Maven仓库。你可以通过阿里云提供的“maven”标签来获取: ```xml <repositories> <repository> <id>central</id> <name>Maven Central Repository</name> <url>https://mirrors.aliyun.com/maven</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> ``` 注意替换`https://mirrors.aliyun.com/maven`为实际的阿里云镜像URL。 2. **选择合适的依赖**:如果你想从腾讯云下载特定的库或依赖,通常需要访问腾讯云的官方网站找到相应的JAR包或者查找其发布的Maven坐标(groupId, artifactId, version),然后在`dependencies`部分添加对应的`<dependency>`标签。 ```xml <dependencies> <!-- 例如,如果有一个名为tencent-cloud-sdk的依赖 --> <dependency> <groupId>com.tencent.cloud</groupId> <artifactId>tencent-cloud-sdk</artifactId> <version>版本号</version> </dependency> </dependencies> ``` 3. **构建和部署**:配置完成后,运行`mvn install`命令安装依赖,`mvn clean package deploy`可以将项目打包并发布到远程仓库。 4. **设置环境变量**:在你的项目运行环境中,可能还需要设置指向腾讯云仓库的系统属性,如`maven.repo.local`指向阿里云仓库的本地存储路径。 ```bash export MAVEN_REPOSITORY_URL=https://mirrors.aliyun.com/maven ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值