Go SDK

Updated at:

This topic shows how to call the Go SDK and provides code examples.

Get the SDK

go get -u github.com/aliyun/alibaba-cloud-sdk-go/sdk

Configure environment variables

The Alibaba Cloud SDK for Go lets you configure default access credentials by setting the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables. When you call an API, the SDK reads your AccessKey from these variables to complete authentication.

Important

An Alibaba Cloud account AccessKey grants full access to all APIs. For enhanced security, we recommend using a RAM user for API calls or daily operations. This practice prevents the accidental disclosure of your AccessKey.

Configuration

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

  • For Linux and macOS

    Run the following commands:

    export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>

    Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.

  • For Windows

    1. Create two environment variables, ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and set their values to your AccessKey ID and AccessKey Secret.

    2. Restart Windows for the changes to take effect.

Address extraction

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)


// Tests the address extraction service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "ExtractAddress"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"4281D228-48C2-1663-B7E0-1B703ADC9206",
    "Data":"{\"location_extract\":[{\"start\":0,\"end\":11,\"type\":\"LOC\",\"word\":\"杭州市文一西路969号\"}],\"status\":\"OK\",\"time_used\":{\"rt\":{\"location_extract\":0.006235361099243164},\"start\":1669016669.424701}}"
}

Name extraction

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)


// Tests the name extraction service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "ExtractName"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"163D719A-379E-1021-89C6-83AA886B0C9E",
    "Data":"{\"person_extract\":[{\"start\":0,\"end\":2,\"type\":\"PER\",\"word\":\"张三\"}],\"status\":\"OK\",\"time_used\":{\"rt\":{\"person_extract\":0.004713296890258789},\"start\":1669016729.012622}}"
}

Phone number extraction

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)


// Tests the phone number extraction service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "ExtractPhone"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "18111111111杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"33646CAD-305C-11F9-A862-1BDEDB05069D",
    "Data":"{\"phone_extract\":[{\"start\":0,\"end\":11,\"type\":\"TEL\",\"word\":\"18111111111\"}],\"status\":\"OK\",\"time_used\":{\"rt\":{\"phone_extract\":0.007447242736816406},\"start\":1669016868.6523287}}"
}

Administrative division parsing

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the administrative division parsing service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "GetAddressDivisionCode"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"59D48D7E-5FA4-1284-ABEF-BB979B7A3782",
    "Data":"{\"division_info\":{\"divcode\":\"330110005011\",\"division_name\":\"浙江省;杭州市;余杭区;五常街道\"},\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.013077259063720703,\"division_info\":0.005147695541381836,\"segment\":0.0003695487976074219,\"address_correct\":0.0047953128814697266,\"complete\":0.00012731552124023438,\"address_search\":0.14465618133544922,\"structure\":0.00008034706115722656},\"start\":1669016944.2376196}}"
}

Postal code recognition

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)


// Tests the postal code recognition service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "GetZipcode"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"D4E53E8A-35FC-13A7-A8A7-9C016B5AE826",
    "Data":"{\"zipcode\":\"311100\",\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.011469125747680664,\"zipcode\":0.00478672981262207,\"segment\":0.0003814697265625,\"address_correct\":0.002938508987426758,\"complete\":0.00012087821960449219,\"address_search\":0.13212800025939941,\"structure\":0.00007414817810058594},\"start\":1669017029.1387427}}"
}

Address completion

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)


// Tests the address completion service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "CompleteAddress"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"8221FF19-3B3B-1093-BA27-470D6C477931",
    "Data":"{\"complete\":\"prov=浙江省\\tcity=杭州市\\tdistrict=余杭区\\ttown=五常街道\\troad=文一西路\\troads=文一西路\\troadno=969号\\tdetail=road:文一西路, roadno:969号\",\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.01302337646484375,\"segment\":0.0003464221954345703,\"address_correct\":0.00407862663269043,\"complete\":0.00012874603271484375,\"address_search\":0.13558363914489746,\"structure\":0.0000782012939453125},\"start\":1669017094.494578}}"
}

Address correction

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the address correction service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "CorrectAddress"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"FE17801D-CF15-1D5C-99AC-CBD269F8E372",
    "Data":"{\"address_correct\":[\"杭州市=city\\t文一西路=road\\t969号=roadno\"],\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.011129379272460938,\"segment\":0.0003046989440917969,\"address_correct\":0.002922534942626953},\"start\":1669017166.8149192}}"
}

Address structuring

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the address structuring service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "StructureAddress"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"3276695D-AA80-1690-8CDB-14ABA6141B69",
    "Data":"{\"structure\":\"city=杭州市\\tdistrict=余杭区\\troad=文一西路\\troads=文一西路\\troadno=969号\\tdetail=road:文一西路, roadno:969号\",\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.00970602035522461,\"structure\":0.00007295608520507812},\"start\":1669017236.508286}}"
}

Address similarity

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the address similarity service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "GetAddressSimilarity"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市阿里巴巴西溪园区;杭州市文一西路969号1号楼"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"5C34C106-ED5A-1000-915E-DCB3062A1C7B",
    "Data":"{\"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.38626623153686523},\"start\":1669017549.8823686}}"
}

Waybill information extraction

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the waybill information extraction service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "ExtractExpress"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"A6585271-39E5-16E7-9B8B-B03612AAD8EC",
    "Data":"{\"express_extract\":{\"house_info\":\"\",\"poi_info\":\"文一西路969号\",\"town\":\"五常街道\",\"city\":\"杭州市\",\"district\":\"余杭区\",\"tel\":\"\",\"addr_info\":\"文一西路969号\",\"per\":\"\",\"prov\":\"浙江省\"},\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.014315128326416016,\"segment\":0.0036001205444335938,\"address_correct\":0.0047457218170166016,\"complete\":0.0001277923583984375,\"express_extract\":0.0000152587890625,\"address_search\":0.1396617889404297,\"structure\":0.00007295608520507812},\"start\":1669017633.0212653}}"
}

Address type recognition

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the address type recognition service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "ClassifyPOI"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"60B446C1-806F-11AD-B2C2-5D1709C462D1",
    "Data":"{\"poi_category\":\"商务住宅#industrial park#industrial park\",\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.009667396545410156,\"segment\":0.0003724098205566406,\"poi_category\":0.0866851806640625,\"address_correct\":0.0020608901977539062,\"complete\":0.0001289844512939453,\"poi_predict\":0.009099721908569336,\"address_search\":0.11052727699279785,\"structure\":0.0000782012939453125},\"start\":1669017987.9801195}}"
}

POI prediction

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the POI prediction service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "PredictPOI"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"4E8A3FD7-BC8A-1D3F-92BA-876E13C37739",
    "Data":"{\"poi_predict\":\"阿里巴巴西溪园区;阿里巴巴西溪亲橙里;西溪悦城\",\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.0228574275970459,\"segment\":0.0003662109375,\"address_correct\":0.0051538944244384766,\"complete\":0.00013828277587890625,\"poi_predict\":0.010706424713134766,\"address_search\":0.1489100456237793,\"structure\":0.0000820159912109375},\"start\":1669018100.805084}}"
}

Coordinate system conversion

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the coordinate system conversion service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "TransferCoord"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["SrcCoord"] = "gcj02"
	request.QueryParams["Text"] = "120.026268,30.279164"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"7BB7822F-5DD1-1F8E-868C-43C00B8A6C24",
    "Data":"{\"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.0016350746154785156},\"start\":1669018416.626254}}"
}

General geocoding (POI level)

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the general geocoding (POI level) service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "GetAddressGeocode"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"7004E6CC-D80E-194D-A978-40F82503DAB2",
    "Data":"{\"offline_geocode\":{\"wgs84\":\"120.02099798073618,30.281364166381348\",\"level\":\"roadno\",\"gcj02\":\"120.025746,30.278984\"},\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.009946823120117188,\"div_search\":0.003939390182495117,\"segment\":0.0003464221954345703,\"geocode\":0.00010848045349121094,\"address_correct\":0.004141807556152344,\"address_search\":0.1393885612487793,\"structure\":0.00007653236389160156},\"start\":1669018504.6332119}}"
}

Address assessment

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the address assessment service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "AddressAssessment"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "阿里巴巴西溪园区"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"11D06FA5-A2C8-5518-8F07-AA7E721FB68D",
    "Data":"{\"address_assessment\":{\"error_code\":\"0102060003000000\",\"error_content\":[\"缺少信息,但不影响理解\",\"乡镇级行政区划部分缺失(无法补齐)\",\"没有poi \"]},\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.010349273681640625,\"address_assessment\":0.4159200191497803,\"structure\":0.00007796287536621094},\"start\":1680762839.7492118}}"
}

Address search

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)


// Tests the address search service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "GetAddressSearch"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "张三杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"469182EF-FDA5-1871-A843-A7409CC68FBA",
    "Data":"{\"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.009841442108154297,\"segment\":0.0036520957946777344,\"address_correct\":0.004261493682861328,\"address_search\":0.13625621795654297,\"structure\":0.00007653236389160156},\"start\":1669018657.4268672}}"
}

Address autocomplete

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
) 

// Tests the address autocomplete service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "GetInputSearch"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()
	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
    "RequestId":"2506A837-CD21-11E8-ADDE-818BC80608BA",
    "Data":"{\"input_search\":[\"浙江省 杭州市 余杭区 五常街道  文一西路 969号  阿里巴巴西溪A区\",\"浙江省 杭州市 余杭区 余杭街道  文一西路 1888号  杭州余杭万达广场\",\"浙江省 杭州市 余杭区 仓前街道 文一西路 1378号 杭州师范大学科技园(文一西路)\",\"浙江省 杭州市 余杭区 余杭街道  文一西路 1816号  中国石化加油站\",\"浙江省 杭州市 余杭区 仓前街道  文一西路 1500号  余杭组团市民之家\"],\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.009873151779174805,\"input_search\":0.15682721138000488,\"structure\":0.00007510185241699219},\"start\":1669018716.1147087}}"
}

Spoken address recognition

Request example

// Tests the spoken address recognition service.
func InputAsrAddress() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "InputAsrAddress"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "嗯,呃秦皇岛市抚宁抚宁区淮海路66号嗯花筑米十海景旅拍民宿201室。"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
	"RequestId": "7D3DC203-DC45-14FD-A9DB-1308201F7E74",
	"Data": "{\"asr_address_input\":{\"house_info\":\"201室\",\"struct\":\"prov=河北省\\tcity=秦皇岛市\\tdistrict=抚宁区\\troad=环海路\\troadno=66号\\tpoi=花筑米十海景旅拍民宿\\troomno=201室\",\"poi_info\":\"环海路66号花筑米十海景旅拍民宿\",\"town\":\"\",\"city\":\"秦皇岛市\",\"district\":\"抚宁区\",\"addr_info\":\"环海路66号花筑米十海景旅拍民宿201室\",\"prov\":\"河北省\"},\"status\":\"OK\",\"time_used\":{\"rt\":{\"asr_address_input\":0.06748580932617188},\"start\":1676019245.7703812}}"
}

Street address standardization

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

// Tests the street address standardization service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "StreetStd"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市文一西路969号"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
		"RequestId":"DF22BFA4-4690-130E-AB9F-EB3E1F14F828",
		"Data":"{\"street_std\":\"prov=浙江省\\tcity=杭州市\\tdistrict=余杭区\\ttown=五常街道\\troad=文一西路\\troadno=969号\",\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.010551214218139648,\"street_std\":0.0004742145538330078,\"segment\":0.0003879070281982422,\"address_correct\":0.0031676292419433594,\"address_search\":0.12173581123352051,\"structure\":0.00008463859558105469},\"start\":1675133490.0090132}}"
}

Multi-source address unification

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)
// Tests the multi-source address unification service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "OneIdAddress"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "恒生科技园(文一西路)37号1单元怡恩贝"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
		"RequestId":"8B8B815B-4F57-1143-922D-95AB0CC1DF41",
		"Data":"{\"online_address_unify\":\"ac0c3f0a7e1121e1aadb5f67ae88fd45\",\"status\":\"OK\",\"time_used\":{\"rt\":{\"basic_chunking\":0.048096656799316406,\"online_address_unify\":0.33766984939575195,\"segment\":0.00047779083251953125,\"address_correct\":0.003159046173095703,\"address_search\":0.12044072151184082,\"structure\":0.00010132789611816406},\"start\":1675133523.743318}}"
}

Address inference from dialog context

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)
// Tests the address inference from dialog context service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "AddressInference"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "我在阿里巴巴门口被车撞了,滨江区的"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
		"RequestId":"5C8CD06A-5278-1A6B-A8C3-9C36F398F52C",
    "Data":"{\"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.0066776275634765625,\"address_inference\":0.10722494125366211},\"start\":1675133541.6845055}}"
}

High-precision geocoding (building level)

Request example

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)
// Tests the high-precision geocoding (building level) service.
func main() {
	client, err := sdk.NewClientWithAccessKey("cn-hangzhou",
		// We strongly recommend that you do not hardcode your AccessKey ID and AccessKey Secret in your code.
		// Hardcoding credentials poses a security risk and may lead to the compromise of all resources in your account.
		// This example uses environment variables for authentication. Ensure they are configured before running this code.
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
		os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
	if err != nil {
		// Handle exceptions
		panic(err)
	}
	// Create a common request
	request := requests.NewCommonRequest()
	// Set the request method
	request.Method = "POST"
	// Specify the product
	request.Product = "address-purification"
	// If a domain is specified, endpoint resolution is skipped. This is required for services that use Bearer Token authentication.
	request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
	// Specify the product version
	request.Version = "2019-11-18"
	// Specify the API name
	request.ApiName = "HpGeocode"
	request.QueryParams["ServiceCode"] = "addrp"
	request.QueryParams["AppKey"] = "<your-app-key>"
	request.QueryParams["Text"] = "杭州市阿里巴巴西溪a区"
	request.QueryParams["DefaultProvince"] = "浙江省"
	request.QueryParams["DefaultCity"] = "杭州市"
	request.QueryParams["DefaultDistrict"] = "余杭区"
	// Convert the common request to an AcsRequest
	request.TransToAcsRequest()

	response, _ := client.ProcessCommonRequest(request)
	fmt.Println(response)
}

Response example

{
		"RequestId":"F6452C7B-BF33-1F2E-B48E-D219C68DEFBB",
		"Data":"{\"hpgeocode\":{\"level\":\"subpoi\",\"gcj02\":\"120.025746,30.278984\"},\"status\":\"OK\",\"time_used\":{\"rt\":{\"hpgeocode\":0.4177830219268799},\"start\":1675133555.6189246}}"
 }