JAVA SDK调用方法及示例。
获取SDK
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-address-purification -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-address-purification</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
配置环境变量
阿里云SDK支持通过定义ALIBABA_CLOUD_ACCESS_KEY_ID
和ALIBABA_CLOUD_ACCESS_KEY_SECRET
环境变量来创建默认的访问凭证。调用接口时,程序直接访问凭证,读取您的访问密钥(即AccessKey)并自动完成鉴权。
重要
阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维,避免AccessKey泄露。
配置方法
配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID
和ALIBABA_CLOUD_ACCESS_KEY_SECRET
。
Linux和macOS系统配置方法
执行以下命令:
export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
<access_key_id>
需替换为已准备好的AccessKey ID,<access_key_secret>
替换为AccessKey Secret。Windows系统配置方法
新建环境变量,添加环境变量
ALIBABA_CLOUD_ACCESS_KEY_ID
和ALIBABA_CLOUD_ACCESS_KEY_SECRET
,并写入已准备好的AccessKey ID和AccessKey Secret。重启Windows系统。
地址抽取
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.ExtractAddressRequest;
import com.aliyuncs.address_purification.model.v20191118.ExtractAddressResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 地址抽取服务调用
*/
public class TestExtractAddress {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
ExtractAddressRequest request = new ExtractAddressRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
ExtractAddressResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"location_extract":[
{
"start":0,
"end":11,
"type":"LOC",
"word":"杭州市文一西路969号"
}
],
"status":"OK",
"time_used":{
"rt":{
"location_extract":0.006271839141845703
},
"start":1668996923.173309
}
}
姓名抽取
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.ExtractNameRequest;
import com.aliyuncs.address_purification.model.v20191118.ExtractNameResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 姓名抽取服务测试
*/
public class TestExtractName {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
ExtractNameRequest request = new ExtractNameRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("张三在杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
ExtractNameResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"person_extract":[
{
"start":0,
"end":2,
"type":"PER",
"word":"张三"
}
],
"status":"OK",
"time_used":{
"rt":{
"person_extract":0.006590843200683594
},
"start":1668998070.0616143
}
}
电话号码抽取
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.ExtractPhoneRequest;
import com.aliyuncs.address_purification.model.v20191118.ExtractPhoneResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 电话号码抽取服务测试
*/
public class TestExtractPhone {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
ExtractPhoneRequest request = new ExtractPhoneRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("181****1111杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
ExtractPhoneResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"phone_extract":[
{
"start":0,
"end":11,
"type":"TEL",
"word":"181****1111"
}
],
"status":"OK",
"time_used":{
"rt":{
"phone_extract":0.0076787471771240234
},
"start":1668998324.7981062
}
}
行政区划解析
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.GetAddressDivisionCodeRequest;
import com.aliyuncs.address_purification.model.v20191118.GetAddressDivisionCodeResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 行政区划解析服务测试
*/
public class TestGetAddressDivisionCode {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
GetAddressDivisionCodeRequest request = new GetAddressDivisionCodeRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
GetAddressDivisionCodeResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"division_info":{
"divcode":"330110005000",
"division_name":"浙江省;杭州市;余杭区;五常街道"
},
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.018784761428833008,
"division_info":0.005293130874633789,
"segment":0.0003788471221923828,
"address_correct":0.003320932388305664,
"complete":0.00012564659118652344,
"address_search":0.19436097145080566,
"structure":0.00008368492126464844
},
"start":1668998510.5782871
}
}
邮编识别
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.GetZipcodeRequest;
import com.aliyuncs.address_purification.model.v20191118.GetZipcodeResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 邮编识别服务测试
*/
public class TestGetZipcode {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
GetZipcodeRequest request = new GetZipcodeRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("18111111111杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
GetZipcodeResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"zipcode":"311100",
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.018795490264892578,
"zipcode":0.004938602447509766,
"segment":0.0003688335418701172,
"address_correct":0.003262042999267578,
"complete":0.00015592575073242188,
"address_search":0.19379043579101562,
"structure":0.00008320808410644531
},
"start":1668998734.559096
}
}
地址补全
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.CompleteAddressRequest;
import com.aliyuncs.address_purification.model.v20191118.CompleteAddressResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 地址补全服务测试
*/
public class TestCompleteAddress {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
CompleteAddressRequest request = new CompleteAddressRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
CompleteAddressResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"complete":"prov=浙江省\tcity=杭州市\tdistrict=余杭区\ttown=五常街道\troad=文一西路\troads=文一西路\troadno=969号\tdetail=road:文一西路, roadno:969号",
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.01125478744506836,
"segment":0.0003504753112792969,
"address_correct":0.0029888153076171875,
"complete":0.00012612342834472656,
"address_search":0.12113261222839355,
"structure":0.00007939338684082031
},
"start":1668998918.8117056
}
}
地址纠错
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.CorrectAddressRequest;
import com.aliyuncs.address_purification.model.v20191118.CorrectAddressResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 地址纠错服务测试
*/
public class TestCorrectAddress {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
CorrectAddressRequest request = new CorrectAddressRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
CorrectAddressResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"address_correct":[
"杭州市=city\t文一西路=road\t969号=roadno"
],
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.009434223175048828,
"segment":0.00030493736267089844,
"address_correct":0.0020487308502197266
},
"start":1668999096.2482975
}
}
地址结构化
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.StructureAddressRequest;
import com.aliyuncs.address_purification.model.v20191118.StructureAddressResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 地址结构化服务测试
*/
public class TestStructureAddress {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
StructureAddressRequest request = new StructureAddressRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("18111111111杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
StructureAddressResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"structure":"prov=浙江省\tcity=杭州市\tdistrict=余杭区\troad=文一西路\troads=文一西路\troadno=969号\tdetail=redundant:1, redundant:8, redundant:1, redundant:1, redundant:1, redundant:1, redundant:1, redundant:1, redundant:1, redundant:1, redundant:1, road:文一西路, roadno:969号",
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.016843318939208984,
"structure":0.00007843971252441406
},
"start":1668999415.143025
}
}
多地址相似性判断
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.GetAddressSimilarityRequest;
import com.aliyuncs.address_purification.model.v20191118.GetAddressSimilarityResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
*
* @author shuaicheng
* 多地址相似性判断服务测试
*/
public class TestGetAddressSimilarity {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
GetAddressSimilarityRequest request = new GetAddressSimilarityRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市阿里巴巴西溪园区;杭州市文一西路969号1号楼");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
GetAddressSimilarityResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"sim_level":{
"level":"none",
"address_a":"杭州市阿里巴巴西溪园区",
"address_b":"杭州市文一西路969号1号楼",
"is_same":false,
"same_info":"prov=浙江省 city=杭州市 district=余杭区 town=五常街道 road=北侧道路 poi=阿里巴巴西溪园区"
},
"status":"OK",
"time_used":{
"rt":{
"sim_level":0.3559575080871582
},
"start":1668999813.793649
}
}
物流面单信息提取
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.ExtractExpressRequest;
import com.aliyuncs.address_purification.model.v20191118.ExtractExpressResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 物流面单信息提取服务测试
*/
public class TestExtractExpress {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
ExtractExpressRequest request = new ExtractExpressRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("张三在杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
ExtractExpressResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"express_extract":{
"house_info":"",
"poi_info":"文一西路969号",
"town":"五常街道",
"city":"杭州市",
"district":"余杭区",
"tel":"",
"addr_info":"文一西路969号",
"per":"张三",
"prov":"浙江省"
},
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.014468908309936523,
"segment":0.0004544258117675781,
"address_correct":0.003080606460571289,
"complete":0.00012683868408203125,
"express_extract":0.00001430511474609375,
"address_search":0.12194633483886719,
"structure":0.00008344650268554688
},
"start":1669000064.1784253
}
}
地址类型识别
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.ClassifyPOIRequest;
import com.aliyuncs.address_purification.model.v20191118.ClassifyPOIResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 地址类型识别服务测试
*/
public class TestClassifyPOI {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
ClassifyPOIRequest request = new ClassifyPOIRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
ClassifyPOIResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"poi_category":"商务住宅#产业园区#产业园区",
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.00995016098022461,
"segment":0.0003726482391357422,
"poi_category":0.08538699150085449,
"address_correct":0.002130270004272461,
"complete":0.000118255615234375,
"poi_predict":0.009357452392578125,
"address_search":0.10561966896057129,
"structure":0.00007843971252441406
},
"start":1669000261.1281157
}
}
POI预测
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.PredictPOIRequest;
import com.aliyuncs.address_purification.model.v20191118.PredictPOIResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* poi预测服务测试
*/
public class TestPredictPOI {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
PredictPOIRequest request = new PredictPOIRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("18111111111杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
PredictPOIResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"poi_predict":"阿里巴巴西溪园区;阿里巴巴西溪亲橙里;西溪悦城",
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.019006729125976562,
"segment":0.0003688335418701172,
"address_correct":0.0032453536987304688,
"complete":0.0001442432403564453,
"poi_predict":0.009587526321411133,
"address_search":0.14672160148620605,
"structure":0.00008487701416015625
},
"start":1669000421.0329113
}
}
坐标系转换
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.TransferCoordRequest;
import com.aliyuncs.address_purification.model.v20191118.TransferCoordResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 坐标系转换服务测试
*/
public class TestTransferCoord {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
TransferCoordRequest request = new TransferCoordRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("120.026268,30.279164");
request.setSrcCoord("gcj02");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
TransferCoordResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"coord_transfer":{
"BD09":"120.032768,30.285238",
"CGCS2000":"120.021519,30.281543",
"WGS84":"120.021519,30.281543",
"GCJ02":"120.026268,30.279164"
},
"status":"OK",
"time_used":{
"rt":{
"coord_transfer":0.0018019676208496094
},
"start":1669000765.048758
}
}
通用经纬度查询(POI级别)
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.GetAddressGeocodeRequest;
import com.aliyuncs.address_purification.model.v20191118.GetAddressGeocodeResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 通用经纬度查询(POI级别)服务测试
*/
public class TestGetAddressGeocode {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
GetAddressGeocodeRequest request = new GetAddressGeocodeRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市阿里巴巴西溪园区");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
GetAddressGeocodeResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"offline_geocode":{
"wgs84":"120.02099798073618,30.281364166381348",
"level":"roadno",
"gcj02":"120.025746,30.278984"
},
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.025951385498046875,
"div_search":0.00095367431640625,
"segment":0.0003399848937988281,
"geocode":0.0001289844512939453,
"address_correct":0.0031554698944091797,
"address_search":0.14507341384887695,
"structure":0.00008082389831542969
},
"start":1669000942.9456813
}
}
地址异常检测
请求示例
package com.alibaba.demo;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.UUID;
/**
* @author shuaicheng
* 新 - 异常地址判定服务测试
*/
public class TestAddressAssessment {
public static void main(String[] args) {
DefaultProfile defaultProfile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(defaultProfile);
// 创建API请求并设置参数
CommonRequest request = new CommonRequest();
request.setSysDomain("address-purification.cn-hangzhou.aliyuncs.com");
request.setSysVersion("2019-11-18");
request.setSysProduct("address-purification");
request.setSysLocationProduct("addrp");
//设置要请求的服务
request.setSysAction("AddressAssessment");
//设置请求方式
request.setSysMethod(MethodType.POST);
request.setHttpContentType(FormatType.FORM);
//请求头
request.putHeadParameter("x-acs-signature-method", "HMAC-SHA1");
request.putHeadParameter("x-acs-signature-nonce", UUID.randomUUID().toString());
//设置项目token
request.putBodyParameter("AppKey", "<your-app-key>");
//设置请求参数
request.putBodyParameter("Text", "阿里巴巴西溪园区");
request.putBodyParameter("DefaultCity", "杭州市");
request.putQueryParameter("AcceptLanguage", "zh-CN");
try {
CommonResponse response = client.getCommonResponse(request);
String data = response.getData();
JSONObject jsonObject = JSONObject.parseObject(data);
JSONObject data1 = jsonObject.getJSONObject("Data");
System.out.println(data1);
} catch (ServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
返回示例
{
"address_assessment":{
"error_code":"0102050204000000",
"error_content":[
"缺少信息,但不影响理解",
"区县级行政区划部分缺失(无法补齐)",
"路名缺失",
"缺少行政村"
]
},
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.012493610382080078,
"address_assessment":0.16082525253295898,
"structure":0.00007700920104980469
},
"start":1680762367.9748535
}
}
地址搜索
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.GetAddressSearchRequest;
import com.aliyuncs.address_purification.model.v20191118.GetAddressSearchResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 地址搜索服务测试
*/
public class TestGetAddressSearch {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
GetAddressSearchRequest request = new GetAddressSearchRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("18111111111杭州市文一西路969号");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
GetAddressSearchResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"address_search":[
{
"address":"文一西路969号",
"name":"阿里巴巴西溪A区",
"std_addr":"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区"
},
{
"address":"文一西路969号阿里巴巴西溪亲橙里1层",
"name":"菲住布渴酒店",
"std_addr":"浙江省 杭州市 余杭区 五常街道 文一西路 969号 菲住布渴酒店"
},
{
"address":"文一西路969号阿里巴巴西溪A区",
"name":"阿里巴巴西溪A区(A5门)",
"std_addr":"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区(A5门)"
},
{
"address":"文一西路969号阿里巴巴西溪A区",
"name":"阿里巴巴西溪A区(A3门)",
"std_addr":"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区(A3门)"
},
{
"address":"文一西路969号阿里巴巴西溪A区",
"name":"阿里巴巴西溪A区(A6门)",
"std_addr":"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区(A6门)"
}
],
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.01730632781982422,
"segment":0.00045418739318847656,
"address_correct":0.0021839141845703125,
"address_search":0.13813257217407227,
"structure":0.00008058547973632812
},
"start":1669001326.1229222
}
}
地址输入联想
请求示例
package com.alibaba.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.GetInputSearchRequest;
import com.aliyuncs.address_purification.model.v20191118.GetInputSearchResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author shuaicheng
* 地址输入联想服务测试
*/
public class TestGetInputSearch {
public static void main(String[] args) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
GetInputSearchRequest request = new GetInputSearchRequest();
request.setAppKey("<your-app-key>");
request.setServiceCode("addrp");
request.setText("杭州市阿里巴巴西溪园区;杭州市文一西路969号1号楼");
request.setDefaultProvince("浙江省");
request.setDefaultCity("杭州市");
request.setDefaultDistrict("余杭区");
GetInputSearchResponse response = client.getAcsResponse(request);
System.out.println(response.getData());
}
}
返回示例
{
"input_search":[
"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区",
"浙江省 杭州市 余杭区 五常街道 文一西路 969号 A5号楼 阿里巴巴西溪A区(A区访客中心)",
"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区(A5门)",
"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区(A3门)",
"浙江省 杭州市 余杭区 五常街道 文一西路 阿里巴巴西溪园区(公交站)"
],
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.02606368064880371,
"input_search":0.23061370849609375,
"structure":0.00008249282836914062
},
"start":1669001660.1672509
}
}
门址标准化
请求示例
package com.alibaba.demo;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.UUID;
/**
* @author shuaicheng
* 门址标准化服务测试
*/
public class TestStreetStd {
public static void main(String[] args) {
DefaultProfile defaultProfile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(defaultProfile);
// 创建API请求并设置参数
CommonRequest request = new CommonRequest();
request.setSysDomain("address-purification.cn-hangzhou.aliyuncs.com");
request.setSysVersion("2019-11-18");
request.setSysProduct("address-purification");
request.setSysLocationProduct("addrp");
//设置要请求的服务
request.setSysAction("StreetStd");
//设置请求方式
request.setSysMethod(MethodType.POST);
request.setHttpContentType(FormatType.FORM);
//请求头
request.putHeadParameter("x-acs-signature-method", "HMAC-SHA1");
request.putHeadParameter("x-acs-signature-nonce", UUID.randomUUID().toString());
//设置项目token
request.putBodyParameter("AppKey", "<your-app-key>");
//设置请求参数
request.putBodyParameter("Text", "杭州市文一西路969号");
request.putBodyParameter("DefaultCity", "杭州市");
request.putQueryParameter("AcceptLanguage", "zh-CN");
try {
CommonResponse response = client.getCommonResponse(request);
String data = response.getData();
JSONObject jsonObject = JSONObject.parseObject(data);
JSONObject data1 = jsonObject.getJSONObject("Data");
System.out.println(data1);
} catch (ServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
返回示例
{
"street_std":"prov=浙江省\tcity=杭州市\tdistrict=余杭区\ttown=五常街道\troad=文一西路\troadno=969号",
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.010355472564697266,
"street_std":0.0001628398895263672,
"segment":0.0003783702850341797,
"address_correct":0.0030519962310791016,
"address_search":0.12972450256347656,
"structure":0.000080108642578125
},
"start":1675067580.6475735
}
}
语音地址输入识别
请求示例
package com.alibaba.demo;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.UUID;
/**
* @author shuaicheng
* 语音地址识别服务测试
*/
public class TestInputAsrAddress {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
// 创建API请求并设置参数
CommonRequest request = new CommonRequest();
request.setSysDomain("address-purification.cn-hangzhou.aliyuncs.com");
request.setSysVersion("2019-11-18");
request.setSysProduct("address-purification");
request.setSysLocationProduct("addrp");
//设置要请求的服务
request.setSysAction("InputAsrAddress");
//设置请求方式
request.setSysMethod(MethodType.POST);
request.setHttpContentType(FormatType.FORM);
//请求头
request.putHeadParameter("x-acs-signature-method", "HMAC-SHA1");
request.putHeadParameter("x-acs-signature-nonce", UUID.randomUUID().toString());
//设置项目token
request.putBodyParameter("AppKey", "<your-app-key>");
request.putQueryParameter("AcceptLanguage", "zh-CN");
request.setHttpContentType(FormatType.FORM);
try {
request.putBodyParameter("Text", "未到过武汉,从未接触武汉回来的人员,目前在平昌镇龙镇元顶村家里未出门,身体健康");
long t1 = System.currentTimeMillis();
CommonResponse response = client.getCommonResponse(request);
long t2 = System.currentTimeMillis();
System.out.println(response.getData());
}
catch (ServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientException e) {
// TODO Auto-generated catch block
System.out.println(e.getErrCode());
System.out.println(e.getErrMsg());
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
返回示例
{
"RequestId": "F72EC1D4-CE9E-119B-B58A-66E59B2C40CC",
"Data": "{\"asr_address_input\":{\"house_info\":\"\",\"struct\":\"prov=湖北省\\tcity=武汉市\\tcommunity=园丁村\\tpoi=家里未出门\",\"poi_info\":\"园丁村家里未出门\",\"town\":\"\",\"city\":\"武汉市\",\"district\":\"\",\"addr_info\":\"园丁村家里未出门\",\"prov\":\"湖北省\"},\"status\":\"OK\",\"time_used\":{\"rt\":{\"asr_address_input\":0.1976015567779541},\"start\":1676018776.1014452}}"
}
多源地址归一
请求示例
package com.alibaba.demo;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.UUID;
/**
* @author shuaicheng
* 多源地址归一服务测试
*/
public class TestOneIdAddress {
public static void main(String[] args) {
DefaultProfile defaultProfile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(defaultProfile);
// 创建API请求并设置参数
CommonRequest request = new CommonRequest();
request.setSysDomain("address-purification.cn-hangzhou.aliyuncs.com");
request.setSysVersion("2019-11-18");
request.setSysProduct("address-purification");
request.setSysLocationProduct("addrp");
//设置要请求的服务
request.setSysAction("OneIdAddress");
//设置请求方式
request.setSysMethod(MethodType.POST);
request.setHttpContentType(FormatType.FORM);
//请求头
request.putHeadParameter("x-acs-signature-method", "HMAC-SHA1");
request.putHeadParameter("x-acs-signature-nonce", UUID.randomUUID().toString());
//设置项目token
request.putBodyParameter("AppKey", "<your-app-key>");
//设置请求参数
request.putBodyParameter("Text", "恒生科技园(文一西路)37号1单元怡恩贝");
request.putBodyParameter("DefaultCity", "杭州市");
request.putQueryParameter("AcceptLanguage", "zh-CN");
try {
CommonResponse response = client.getCommonResponse(request);
String data = response.getData();
JSONObject jsonObject = JSONObject.parseObject(data);
JSONObject data1 = jsonObject.getJSONObject("Data");
System.out.println(data1);
} catch (ServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
返回示例
{
"online_address_unify":"a578b39633726c377ea18de669b3efe7",
"status":"OK",
"time_used":{
"rt":{
"basic_chunking":0.06006503105163574,
"online_address_unify":0.3345825672149658,
"segment":0.00047278404235839844,
"address_correct":0.003100156784057617,
"address_search":0.12077140808105469,
"structure":0.00008606910705566406
},
"start":1675070211.2347264
}
}
对话上下文地址推理
请求示例
package com.alibaba.demo;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.UUID;
/**
* @author shuaicheng
* 对话上下文地址推理服务测试
*/
public class TestAddressInference {
public static void main(String[] args) {
DefaultProfile defaultProfile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(defaultProfile);
// 创建API请求并设置参数
CommonRequest request = new CommonRequest();
request.setSysDomain("address-purification.cn-hangzhou.aliyuncs.com");
request.setSysVersion("2019-11-18");
request.setSysProduct("address-purification");
request.setSysLocationProduct("addrp");
//设置要请求的服务
request.setSysAction("AddressInference");
//设置请求方式
request.setSysMethod(MethodType.POST);
request.setHttpContentType(FormatType.FORM);
//请求头
request.putHeadParameter("x-acs-signature-method", "HMAC-SHA1");
request.putHeadParameter("x-acs-signature-nonce", UUID.randomUUID().toString());
//设置项目token
request.putBodyParameter("AppKey", "<your-app-key>");
//设置请求参数
request.putBodyParameter("Text", "我在阿里巴巴门口被车撞了,滨江区的");
request.putBodyParameter("DefaultCity", "杭州市");
request.putQueryParameter("AcceptLanguage", "zh-CN");
try {
CommonResponse response = client.getCommonResponse(request);
String data = response.getData();
JSONObject jsonObject = JSONObject.parseObject(data);
JSONObject data1 = jsonObject.getJSONObject("Data");
System.out.println(data1);
} catch (ServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
返回示例
{
"address_inference":[
{
"address":"网商路699号",
"divcode":"330108",
"name":"阿里巴巴滨江园区",
"id":"B0FFG083SL",
"lxly":"30.1896,120.190371",
"std_addr":"浙江省 杭州市 滨江区 长河街道 网商路 699号 阿里巴巴滨江园区"
},
{
"address":"文一西路969号",
"divcode":"330110",
"name":"阿里巴巴西溪A区",
"id":"B023B1D4BX",
"lxly":"30.278984,120.025746",
"std_addr":"浙江省 杭州市 余杭区 五常街道 文一西路 969号 阿里巴巴西溪A区"
},
{
"address":"溪望路",
"divcode":"330110",
"name":"阿里巴巴西溪B区",
"id":"B0FFGUEOJ9",
"lxly":"30.275962,120.027276",
"std_addr":"浙江省 杭州市 余杭区 五常街道 溪望路 阿里巴巴西溪B区"
}
],
"status":"OK",
"time_used":{
"rt":{
"dialog_extract":0.0078012943267822266,
"address_inference":3.235727548599243
},
"start":1675070387.20365
}
}
高精度经纬度查询(楼栋级别)
请求示例
package com.alibaba.demo;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.address_purification.model.v20191118.ExtractPhoneRequest;
import com.aliyuncs.address_purification.model.v20191118.ExtractPhoneResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.UUID;
/**
* @author shuaicheng
* 高精度经纬度查询(楼栋级别)服务测试
*/
public class TestHpGeocode {
public static void main(String[] args) throws ClientException {
DefaultProfile defaultProfile = DefaultProfile.getProfile(
"cn-hangzhou",
// 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// 本示例以将AccessKey ID和AccessKey Secret保存到环境变量为例说明。运行本代码示例之前,请先配置环境变量。
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(defaultProfile);
// 创建API请求并设置参数
CommonRequest request = new CommonRequest();
request.setSysDomain("address-purification.cn-hangzhou.aliyuncs.com");
request.setSysVersion("2019-11-18");
request.setSysProduct("address-purification");
request.setSysLocationProduct("addrp");
//设置要请求的服务
request.setSysAction("HpGeocode");
//设置请求方式
request.setSysMethod(MethodType.POST);
request.setHttpContentType(FormatType.FORM);
//请求头
request.putHeadParameter("x-acs-signature-method", "HMAC-SHA1");
request.putHeadParameter("x-acs-signature-nonce", UUID.randomUUID().toString());
//设置项目token
request.putBodyParameter("AppKey", "<your-app-key>");
//设置请求参数
request.putBodyParameter("Text", "杭州市阿里巴巴西溪a区");
request.putBodyParameter("DefaultCity", "杭州市");
request.putQueryParameter("AcceptLanguage", "zh-CN");
try {
CommonResponse response = client.getCommonResponse(request);
String data = response.getData();
JSONObject jsonObject = JSONObject.parseObject(data);
JSONObject data1 = jsonObject.getJSONObject("Data");
System.out.println(data1);
} catch (ServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
返回示例
{
"hpgeocode":{
"level":"subpoi",
"gcj02":"120.025746,30.278984"
},
"status":"OK",
"time_used":{
"rt":{
"hpgeocode":0.4139995574951172
},
"start":1675070463.4350975
}
}
文档内容是否对您有帮助?