具有Streetlayer的地址验证API

There is so much of our web and eCommerce that consumers take for granted: payment types and validation, exchange rates, etc.  One of the aspects of eCommerce that should be a given, from both a developer and consumer perspective, is address handling.  We'd like to think the consumer enters their address correctly but the risk is if the don't that their experiences gets ruined by the shipping company not finding the address or, worse yet, a situation where the package is lost and you need to incur a loss shipping them another item (assuming you'd prefer to avoid a contentious fight with the consumer about whose fault the problem is).

消费者认为我们的网络和电子商务有很多东西:付款类型和验证,汇率等。从开发人员和消费者的角度来看,应该考虑的电子商务的一个方面是地址处理。 我们想以为消费者正确输入了地址,但是风险是,如果不是因为运输公司找不到他们的体验而导致他们的经历找不到地址,或者更糟糕的是,包裹丢失了,您需要运送其他物品会造成损失(假设您希望避免与消费者就问题出在谁身上进行争执)。

Of course eCommerce isn't the only reason for address validation and lookup.  You may want coordinates to load a Google Map, you may want to get the user's county, you may want to get zip code information for sales tax calculation -- the use cases are endless.  streetlayer is the service than can perform all address validation needs.

当然,电子商务并不是地址验证和查找的唯一原因。 您可能需要坐标来加载Google地图,可能想要获取用户所在的县,可能想要获取邮政编码信息以进行营业税计算-用例无穷无尽。 Streetlayer一项可以执行所有地址验证需求的服务。

快速点击 (Quick Hits)

  • The streetlayer API is super easy to use

    Streetlayer API非常易于使用

  • Get address validation, autocompletion, and geocoding

    获取地址验证,自动完成和地理编码
  • Provides international address information

    提供国际地址信息
  • streetlayer allows JSONP requests

    街机允许JSONP请求
  • Provides HTTPS API usage

    提供HTTPS API用法
  • Clear documentation and code samples

    清晰的文档和代码示例
  • Very competitive pricing

    极具竞争力的价格

使用街机 (Using streetlayer)

streetlayer offers free signup with a generous request allotment for testing.  After you sign up you'll be given an API key to begin development.  Let's have a look at the different ways you can use streetlayer!

streetlayer提供免费注册,并提供大量测试请求。 注册后,您将获得一个API密钥以开始开发。 让我们来看看您可以使用Streetlayer的不同方式!

街头小贩使用技巧 (streetlayer Usage Tips)

A few constants when using the streetlayer API:

使用streetlayer API时的一些常量:

  • All requests are GET requests

    所有请求均为GET请求
  • All requests require an access_key key/value parameter for the API key

    所有请求都需要API密钥的access_key密钥/值参数

  • Adding format=1 to the query string for streetlayer to indent the JSON response

    format=1添加到街道字符串的查询字符串以缩进JSON响应

验证地址 (Validating an Address)

Validating an address is the most common use of address APIs.  Trusting consumers to input information (outside of payment, which is instantly verifiable) can lead to trouble.  If you're going to verify payment information, why wouldn't you verify delivery address information if you can?

验证地址是地址API的最常见用法。 信任消费者输入信息(付款之外的信息,可以立即验证)可能会导致麻烦。 如果要验证付款信息,为什么不可以验证交货地址信息呢?

Once your customer provides your web or native app with their address information, the first step should be verifying that information, as it's an easy HTTP request to save you shipping and billing trouble down the road.  Shoot their given address information to streetlayer with one simple request:

一旦您的客户向您的Web或本机应用程序提供了他们的地址信息,第一步应该是验证该信息,因为这是一个简单的HTTP请求,可以节省您的运输和开票麻烦。 只需一个简单的请求即可将其给定的地址信息拍摄到街道上:


http://apilayer.net/api/validate
    ? access_key = YOUR_ACCESS_KEY
    & address1 = 767 5th Ave  
    & postal_code = 10153  
    & locality = New York  
    & country_code = USA  


In the case of address verification from streetlayer, you'll see the following response:

如果是从街道图层进行地址验证,您将看到以下响应:


{
  "validation_status": "valid",
  "address_components": {
     "country_code_alpha2": "US",
     "country_code_alpha3": "USA",
     "country": "United States",
     "county": "New York County",
     "locality": "New York",
     "postal_code": "10153",
     "region": "New York",
     "street": "5 Avenue",
     "housenumber": "767",
     "neighbourhood": "Midtown"
  },
  "validation_result": {
     "locality": true,
     "county": null,
     "region": null,
     "postal_code": true,
     "street": true,
     "housenumber": true
  },
  "formatted_address": [
     "5 Avenue 767",
     "New York, 10153",
     "United States"
  ],
  "coordinates": {
     "latitude": 40.763554,
     "longitude": -73.972839
  }
}


Note the validation_status key's value of verified -- that confirms that the address is verified as correct.  If an address cannot be verified, you'll see a unsure value.

注意validation_status的键值verified -该地址被验证为正确,确认。 如果无法验证地址,则会看到unsure值。

自动填写地址 (Autocompleting an Address)

In the case that you receive a partial address, or the initial address information isn't verified and you want to suggest a verified address with less information, streetlayer lets you do that:

如果您收到部分地址,或者未验证初始地址信息,并且想建议一个信息较少的经过验证的地址,则可以使用streetlayer进行以下操作:


http://apilayer.net/api/autocomplete
    ? access_key = YOUR_ACCESS_KEY
    & text = 767 5th A  
    & country_code = USA



{
  "success": true,
  "results": [
     {
        "address_components": {
           "country_code_alpha2": "US",
           "country_code_alpha3": "USA",
           "country": "United States",
           "county": "San Diego County",
           "locality": "Chula Vista",
           "postal_code": "91910",
           "region": "California",
           "street": "5th Avenue",
           "housenumber": "767",
           "neighbourhood": "Mid-Broadway District"
        },
        "formatted_address": [
           "5th Avenue 767",
           "Chula Vista, 91910",
           "United States"
        ],
        "coordinates": {
           "latitude": 32.622941,
           "longitude": -117.081476
        }
     },
     {
        "address_components": {
           "country_code_alpha2": "US",
           "country_code_alpha3": "USA",
           "country": "United States",
           "county": "New York County",
           "locality": "New York",
           "postal_code": "10153",
           "region": "New York",
           "street": "5th Avenue",
           "housenumber": "767",
           "neighbourhood": "Midtown"
        },
        "formatted_address": [
           "5th Avenue 767",
           "New York, 10153",
           "United States"
        ],
        "coordinates": {
           "latitude": 40.763528,
           "longitude": -73.972801
        }
     },
     [...]


Presenting a different, verified address to users if their address information is unverified is commonplace and very useful -- a sign to the customer or user that they can no problems their transaction.

如果他们的地址信息未经验证,向用户提供一个不同的,经过验证的地址是司空见惯的,并且非常有用-向客户或用户发出的信号是他们可以毫无问题地交易。

通过坐标获取地址(反向地址解析查询) (Get Address by Coordinates (Reverse Geocode Lookup))

I've focused much of this post on eCommerce but address services like streetlayer have much more utility.  For example, think about retrieving approximate addresses by coordinates.  Why coordinates?  Think about EXIF data from a photo; you can use EXIF coordinate data to find and approximate address of a photo:

我将这篇文章的大部分内容集中在电子商务上,但是地址服务(例如Streetlayer)具有更多的实用性。 例如,考虑考虑通过坐标检索近似地址。 为什么要协调? 考虑一下照片中的EXIF数据; 您可以使用EXIF坐标数据来查找和估算照片的地址:


http://apilayer.net/api/reverse
    ? access_key = YOUR_ACCESS_KEY
    & latitude = 40.763528  
    & longitude = -73.972801  



{
  "success": true,
  "results": [
     {
        "address_components": {
           "country_code_alpha2": "US",
           "country_code_alpha3": "USA",
           "country": "United States",
           "county": "New York County",
           "locality": "New York",
           "postal_code": "10153",
           "region": "New York",
           "street": "5 Avenue",
           "housenumber": "767",
           "neighbourhood": "Midtown"
        },
        "formatted_address": [
           "5 Avenue 767",
           "New York, 10153",
           "United States"
        ],
        "coordinates": {
           "latitude": 40.763554,
           "longitude": -73.972839
        }
     },
     {
        "address_components": {
           "country_code_alpha2": "US",
           "country_code_alpha3": "USA",
           "country": "United States",
           "county": "New York County",
           "locality": "New York",
           "postal_code": "10022",
           "region": "New York",
           "street": "East 58 Street",
           "housenumber": "12",
           "neighbourhood": "Midtown"
        },
        "formatted_address": [
           "East 58 Street 12",
           "New York, 10022",
           "United States"
        ],
        "coordinates": {
           "latitude": 40.763268,
           "longitude": -73.972842
        }
     },
     
     [...]                


From those coordinates streetlayer provides the approximate address!

从那些坐标街机提供大概的地址!

True story:  in my first year as a professional web developer, a client was blaming my employer for her eCommerce site's shipments not always making it to customers.  At the time, there was no streetlayer-like service, so we were relying on customers to properly enter information...and it led to me getting angry phone calls.  In the end, streetlayer address verification has the potential to save yourself and your customers from shipment, identity, and other geolocation problems!

真实的故事:在我担任专业Web开发人员的第一年,一位客户指责我的老板是因为其电子商务网站的发货量并不总是发给客户。 当时,没有类似街巷服务的服务,因此我们依靠客户正确输入信息……这使我生气。 最后,街道层地址验证有可能使您自己和您的客户免于发货,身份和其他地理位置问题!

翻译自: https://davidwalsh.name/streetlayer-address-api

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值