当前位置:   article > 正文

具有Streetlayer的地址验证API

address validation 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请求,可以节省您的运输和开票麻烦。 只需一个简单的请求即可将其给定的地址信息拍摄到街道上:

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

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

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

  1. {
  2. "validation_status": "valid",
  3. "address_components": {
  4. "country_code_alpha2": "US",
  5. "country_code_alpha3": "USA",
  6. "country": "United States",
  7. "county": "New York County",
  8. "locality": "New York",
  9. "postal_code": "10153",
  10. "region": "New York",
  11. "street": "5 Avenue",
  12. "housenumber": "767",
  13. "neighbourhood": "Midtown"
  14. },
  15. "validation_result": {
  16. "locality": true,
  17. "county": null,
  18. "region": null,
  19. "postal_code": true,
  20. "street": true,
  21. "housenumber": true
  22. },
  23. "formatted_address": [
  24. "5 Avenue 767",
  25. "New York, 10153",
  26. "United States"
  27. ],
  28. "coordinates": {
  29. "latitude": 40.763554,
  30. "longitude": -73.972839
  31. }
  32. }

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进行以下操作:

  1. http://apilayer.net/api/autocomplete
  2. ? access_key = YOUR_ACCESS_KEY
  3. & text = 767 5th A
  4. & country_code = USA
  1. {
  2. "success": true,
  3. "results": [
  4. {
  5. "address_components": {
  6. "country_code_alpha2": "US",
  7. "country_code_alpha3": "USA",
  8. "country": "United States",
  9. "county": "San Diego County",
  10. "locality": "Chula Vista",
  11. "postal_code": "91910",
  12. "region": "California",
  13. "street": "5th Avenue",
  14. "housenumber": "767",
  15. "neighbourhood": "Mid-Broadway District"
  16. },
  17. "formatted_address": [
  18. "5th Avenue 767",
  19. "Chula Vista, 91910",
  20. "United States"
  21. ],
  22. "coordinates": {
  23. "latitude": 32.622941,
  24. "longitude": -117.081476
  25. }
  26. },
  27. {
  28. "address_components": {
  29. "country_code_alpha2": "US",
  30. "country_code_alpha3": "USA",
  31. "country": "United States",
  32. "county": "New York County",
  33. "locality": "New York",
  34. "postal_code": "10153",
  35. "region": "New York",
  36. "street": "5th Avenue",
  37. "housenumber": "767",
  38. "neighbourhood": "Midtown"
  39. },
  40. "formatted_address": [
  41. "5th Avenue 767",
  42. "New York, 10153",
  43. "United States"
  44. ],
  45. "coordinates": {
  46. "latitude": 40.763528,
  47. "longitude": -73.972801
  48. }
  49. },
  50. [...]

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坐标数据来查找和估算照片的地址:

  1. http://apilayer.net/api/reverse
  2. ? access_key = YOUR_ACCESS_KEY
  3. & latitude = 40.763528
  4. & longitude = -73.972801
  1. {
  2. "success": true,
  3. "results": [
  4. {
  5. "address_components": {
  6. "country_code_alpha2": "US",
  7. "country_code_alpha3": "USA",
  8. "country": "United States",
  9. "county": "New York County",
  10. "locality": "New York",
  11. "postal_code": "10153",
  12. "region": "New York",
  13. "street": "5 Avenue",
  14. "housenumber": "767",
  15. "neighbourhood": "Midtown"
  16. },
  17. "formatted_address": [
  18. "5 Avenue 767",
  19. "New York, 10153",
  20. "United States"
  21. ],
  22. "coordinates": {
  23. "latitude": 40.763554,
  24. "longitude": -73.972839
  25. }
  26. },
  27. {
  28. "address_components": {
  29. "country_code_alpha2": "US",
  30. "country_code_alpha3": "USA",
  31. "country": "United States",
  32. "county": "New York County",
  33. "locality": "New York",
  34. "postal_code": "10022",
  35. "region": "New York",
  36. "street": "East 58 Street",
  37. "housenumber": "12",
  38. "neighbourhood": "Midtown"
  39. },
  40. "formatted_address": [
  41. "East 58 Street 12",
  42. "New York, 10022",
  43. "United States"
  44. ],
  45. "coordinates": {
  46. "latitude": 40.763268,
  47. "longitude": -73.972842
  48. }
  49. },
  50. [...]

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/196243
推荐阅读
相关标签
  

闽ICP备14008679号