需要按顺序对数据库表中的邮政地址进行排序
我正在开发一个 Android 应用程序,其中包含邮政地址路由。
我们希望对数据库表中的每个地址进行排序,以便可以为我们的驱动程序打印出每个地址。当数据库表非常适合时,我们不想花时间自己对地址进行排序。
我正在考虑以某种方式在表中创建一个主键,我们可以轻松地按升序排序。这将使为驱动程序创建清单变得容易。
我正在研究,发现有一个叫做 WOEID(地球上的位置 ID)的东西,我认为它代表一个区域,但我不确定它是否对我们有好处,因为同一社区的 2 个邮政地址可以使用相同的 WOEID。
例如,这 3 个地址具有相同的 WOEID:
100 Bowden St., Lowell, MA
131 Stedman St., Lowell, MA
50 Stromquest Ave., Lowell, MA
使用像 WOEID 这样的单个数字的概念对我们来说是完美的,但我们需要按顺序对这些地址进行排序,以便我们知道哪些地址彼此最接近。
也许我们可以使用一个网站从我们的应用程序内发出请求,为他们提供邮政地址,并且该网站将以我们的应用程序可以解析的格式返回代表该地址的单个数字。
也许有一种方法可以对纬度和经度数字进行地理编码或将其转换为我们可以使用的单个数字。
谢谢。
I'm developing an Android app that has postal address routing in it.
We would like to sort each address in a database table in such a way where each address can be printed out for our driver. We don't want to spend time sorting addresses ourselves when a database table would be ideal for that.
I was thinking somehow to create a primary key in the table on a number that we can easily sort in ascending order. That would make it easy to create a manifest for the driver.
I was researching and found that there was something called WOEID (Where on Earth ID) which I think represents a region but I'm not sure if it would be good for us since 2 postal address in the same neighbourhood could use the same WOEID.
For example these 3 addresses have the same WOEID:
100 Bowden St., Lowell, MA
131 Stedman St., Lowell, MA
50 Stromquest Ave., Lowell, MA
The concept of using a single number like WOEID is perfect for us but we need to sort addresses like these in order so we know which ones are closest to each other.
Maybe there is a web site we can use to send out a request from within our app providing them with the postal address and the site will return a single number representing that address in a format our app can parse.
Maybe there is a way to Geocode or convert latitude and longitude numbers into a single number we can use.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么当多个地址共享同一个WOEID时会出现问题吗?我不知道有多少资源可用,但难道不能将此数据提供给某些 API(例如 Google 地图)并计算从您的位置到那里的距离吗?
如果你想避免谷歌,一个真正基本的方法可能是自己进行计算。 (虽然这更多的是一个估计。)
但是我感觉你想找到总距离的最佳路线,所以我认为你的问题也与 旅行推销员问题
So the problems arise when multiple addresses share the same WOEID? I don't know how many resources are available but couldn't it be in idea to fed this data to some API like Google Maps and calculate the distance from your position to there?
If you want to avoid google a really basic approach could be to do the calculation by yourself. (Though this would be more of an estimation.)
However I got the feeling you want to find the best route over total distance so I think your problem is also related to the travelling salesman problem
我找到了一个允许我进行反向地理编码的网站。它返回纬度和经度。
我做了一些实验,发现我可以将纬度和经度加在一起得到一个数字。由于给网站提供准确的地址所得到的结果并不完全是我想要的结果,所以我只给出了一条街道、城市和美国的州来定位。然后,我可以使用返回的纬度和经度,然后按数字升序对房屋地址进行排序。
例如,我们有许多非常网格化的街道,因此纬度和经度相加所得的 1 个数字代表 1 条特定街道上的许多房屋。在一个街区外的另一条街上我也做了同样的事情。现在我所要做的就是列出数据库表中的所有内容,如下所示:
通过下拉菜单选择城市,也通过下拉菜单选择美国州,然后是每条街道的地理编码号码,后面是家庭号码。
这是我用来获取地理编码以及示例街道地址的网站:
I found a web site that allows me to do a reverse Geocoding. It returns a latitude and longitude.
I experimented a bit and found that I can add the latitude and longitude together to get a single number. Since giving an exact address to the web site will give results not completely what I'm looking for I give it just a street and city and US state to locate. I can then use the latitude and longitude returned and then sort the house addresses in numeric ascending order.
For example we have many streets that are very grid like so 1 number from the adding of the latitude and longitude represent many homes on 1 particular street. On another street a block away I did the same thing. Now all I have to do is just list everything in the database table like this:
City chosen by a dropdown, US state also chosen by a dropdown, then the geocoded number for each street followed by the home numbers.
Here is the web site I used to get the Geocoding along with a sample street address: