Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

检测地址的有效性,并且抓取邮编

package com.zjf.addresschk;

import com.zjf.addresschk.entity.AddressEntity;
import com.zjf.addresschk.entity.InfBaidu;
import com.zjf.addresschk.entity.InfGoogle;
import com.zjf.addresschk.service.AddressChkService;
import com.zjf.addresschk.service.AddressChkServiceBaidu;
import com.zjf.addresschk.service.AddressChkServiceGoogle;

import java.util.List;

/**
 * 地址检测工具
 */
public class App
{
    public static void main( String[] args )
    {

        String inPath = "address.xls";//数据源
        String outPath = inPath.replace(".xls","_result.xls");//输出结果

        //谷歌接口(适用于国外地址,国内也可以用)
        executeGoogle(inPath, outPath);
        //百度接口(适用于查询国内地址)
//        executeBaidu(inPath,outPath);
    }

    public static void executeGoogle(String inPath, String outPath) {
        /*
         *谷歌接口
         */
        String apiKey = "AIzaSyBTSsURxD3JVM3D1FpIvnb-6R6T6b50J9E";

        AddressChkService service = new AddressChkServiceGoogle(new InfGoogle(apiKey));
        executeService(inPath, outPath, service);
    }


    public static void executeBaidu(String inPath, String outPath){
         /*
        百度地图接口
         */
        String ak="XtBOCfgETHRj62T7TM6EDZFA";//百度地图ak
        String sk="TUoG9a5mIU7Ktxp8nTQWWOOqCbALd1is";//百度地图sk
        String interfaceUrl="http://api.map.baidu.com/geocoder/v2/?address={address}&output=json&ak="+ak ;//接口地址
        //调用地址 http://api.map.baidu.com/geocoder/v2/?address=深圳华南城&output=json&ak=XtBOCfgETHRj62T7TM6EDZFA&sn=e1b084959fd2cb566234341143921426

        AddressChkService service = new AddressChkServiceBaidu(new InfBaidu(ak,sk,interfaceUrl));
        executeService(inPath, outPath, service);
    }

    public static void executeService(String inPath, String outPath, AddressChkService service) {
        //获取待检测的地址
        List<AddressEntity> addressList =  service.getAddressStr(inPath);
        //进行检测
        service.checkAddress(addressList);
        //抓取邮编
        service.catchPostcode(addressList);
        //输出结果到excel
        service.outputResult(addressList, outPath);
    }
}

将要检测的地址填入 工程目录下的 address.xls

 运行 src/main/java/com/zjf/addresschk/App.java

Comments ( 0 )

Sign in for post a comment

About

地址检查工具,并抓取邮政编码 spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more