存储用户地址的结构化方式与字符串方式的比较

huangapple go评论58阅读模式
英文:

Storing a structured address vs. a string for a user's address

问题

我正在使用Azure Maps服务,并且虽然它可以接受StructuredAddress,但似乎更喜欢将地址作为字符串传递。换句话说,它想要:

var addr = "15127 NE 24th Street, Redmond, WA 98052 US"

而不是:

var address = new StructuredAddress
{
    CountryCode = "US",
    StreetNumber = "15127",
    StreetName = "NE 24th Street",
    Municipality = "Redmond",
    CountrySubdivision = "WA",
    PostalCode = "98052"
};

这两种存储数据的方式之间的具体权衡是什么?我能想到的是:

字符串优点

  1. 数据库模式 - 数据库中的单个列。
  2. 用户界面 - 自由格式的单个编辑框更快/更容易输入。

结构化优点

  1. 获取所有组件。
  2. 清楚每个组件的含义。

使用任何一种方法,当用户输入其地址时,我将将其传递给服务,然后使用返回的已验证地址。还有其他权衡吗?

英文:

I am diving in to using the Azure Maps service and while it can accept a StructuredAddress, it seems to prefer that it get the address as a string. In other words, it wants:

var addr = "15127 NE 24th Street, Redmond, WA 98052 US"

instead of:

var address = new StructuredAddress
{
    CountryCode = "US",
    StreetNumber = "15127",
    StreetName = "NE 24th Street",
    Municipality = "Redmond",
    CountrySubdivision = "WA",
    PostalCode = "98052"
};

So, not asking for opinions here, but what are the specific trade-offs here between the two ways of storing the data. What I can think of is:

String advantages

  1. DB schema - single column in the database.
  2. U.I. - free form single edit box is quicker/easier to enter

Structured advantages

  1. Get all components
  2. Clear what each component is

With either approach, when the user enters their address I will pass it to the service and then use the returned verified address.

So any other trade-offs?

答案1

得分: 0

如果您使用Azure Maps V2搜索地理编码服务,它在幕后利用Bing地图地理编码器。该地理编码器以能够更好地处理自由格式地址字符串而闻名,而不是结构化地址。这在Bing地图文档中有记录,链接在此处:https://learn.microsoft.com/en-us/bingmaps/getting-started/bing-maps-api-best-practices#use-the-find-by-query-api,“推荐的方法是使用Find by Query API将地址传递为单行查询。” 其中“Find by Query” API 是Bing Maps的自由格式地址字符串地理编码器API。这个见解还没有出现在Azure Maps文档中,我猜测这是因为该API仍处于预览阶段。

至于存储,应该根据您的场景需求来确定存储什么以及如何存储。如果您需要访问地址的某些部分,请存储这些部分。如果只需要地址字符串,请存储地址字符串。如果用户将地址字符串传递到UI并希望基于系统中的地址进行廉价自动建议,请存储自由格式字符串。如果您不介意额外的存储空间(除非您处理数千万或更多的地址,但即使如此,可能不会有很大的成本),也可以存储两者。此外,请确保存储纬度/经度值以实现快速加载和可视化。

英文:

If you are using the Azure Maps V2 Search geocoding service, behind the scenes it leverages the Bing maps geocoder. That geocoder is well known to perform better with freeform address strings than with structured addresses. This is documented in the Bing Maps docs here: https://learn.microsoft.com/en-us/bingmaps/getting-started/bing-maps-api-best-practices#use-the-find-by-query-api "The recommended method is to pass in addresses as single-line queries using the Find by Query API." where the "Find by Query" API is Bing Maps free form address string geocoder API. This insight hasn't made it into the Azure Maps documentation yet, I suspect because this API is still in preview.

As for storage, what and how to store should be based on the needs of your scenario. If you need access to parts of an address, store that. If you need just the address string, store that. If you have users passing in address strings into a UI and want a cheap autosuggest based on addresses in your system, store the free form string. There is nothing wrong with storing both if you are fine with the additional storage space (likely relatively small unless you are working with tens of millions or more addresses, but even then, likely not a big cost. Also be sure to store the latitude/longitude value for fast loading/visualizations.

huangapple
  • 本文由 发表于 2023年5月21日 15:35:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76298789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定