格式化城市/州信息

发布于 2024-10-13 03:44:02 字数 498 浏览 6 评论 0原文

我有一个存储用户的家乡、州和国家的应用程序。我并不特别需要进行验证;应用程序的其他部分不依赖于数据,但我希望格式保持一致,以实现虚荣心,并避免以后在数据库中出现“北卡罗来纳州”、“北卡罗来纳州”、“北卡罗来纳州”等。

有谁知道一种方法来传递 Bing 地图(我更喜欢 Bing 而不是 Google,因为到目前为止我一直在这个项目中使用它)搜索字符串并返回一个带有服务解释的地址的对象? (即传入“北卡罗来纳州夏洛特”并返回“美国北卡罗来纳州夏洛特”)

我查看了 VEPlace (在 MSDN),但我不确定如何确保从 获取我希望的格式名称 属性。有人知道如何最好地解决这个问题吗?

另外,该项目的后端是 ASP.NET MVC,因此如果有一种方法可以在涉及控制器或类似内容的 C# 中完成此操作,那完全没问题。

I have an application which stores the user's home town, state, and country. I don't particularly need to do validation; no other part of the application relies on the data, but I would like the formatting to be consistent for vanity and to avoid later having "North Carolina", "NC", "north carolina" and so forth all in the database.

Does anyone know of a way to pass Bing maps (I would prefer Bing over Google since I've been using it on this project thus far) a search string and get given back an object with the address as interpreted by the service? (i.e. pass in "charlotte, nc" and be given back "Charlotte, North Carolina, United States")

I've looked at VEPlace (on MSDN), but I'm not sure how to ensure I get back the format I'm hoping for from the Name attribute. Anyone have an idea on how best to go about this?

Also, the back-end for the project is ASP.NET MVC, so if there's a way to do it in C# that involves a controller or something similar that's totally fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牵你的手,一向走下去 2024-10-20 03:44:02

我想我可能已经找到了解决方案: GeocodeServiceRequest.ReverseGeocodeRequest 方法(位于 MSDN)返回一个具有 Address 成员的 GeocodeResponse 类。这又具有按照我想要的方式形成地址所需的所有属性。因此,将有一个带有 Action 的控制器来获取地址的字符串形式,它将发送回格式正确的版本。

我将尝试这个并在几个小时内更新代码。它不完全是客户端,这不是最理想的,但看起来它会工作得很好。

I think I may have found the solution: The GeocodeServiceRequest.ReverseGeocodeRequest method (on MSDN) returns a GeocodeResponse class which has an Address member. This in turn has all the attributes required to form the address the way I want. So there will be a controller with an Action to take in the string form of the address, which will send back the properly formatted version.

I'm going to try this and update with code in a couple hours. It's not fully client-side, which is suboptimal, but it looks like it will work well.

高速公鹿 2024-10-20 03:44:02

我怀疑您需要执行以下操作:

  1. 查询 Bing / Google 地图以获取该城市的 lat / lng。
  2. 使用纬度/经度的反向地理编码查找来获得一致的命名约定。 (看起来你已经找到了这个。这里是一个使用这个的链接:http://blog.bobcravens.com/2011/01/a-windows-phone-7-trip-recorder/

如果你像这样分解它,你可能想播种你的#1使用从浏览器的地理定位 API 获取的 lat/lng。

鲍勃

I suspect that you will need to do the following:

  1. Query Bing / Google maps to get the lat / lng for the city.
  2. Use reverse geocode look up of the lat/lng to get a consistent naming convention. (looks like you found this already. here is a link using this: http://blog.bobcravens.com/2011/01/a-windows-phone-7-trip-recorder/)

If you broke it down like this, you may want to seed your #1 with the lat/lng you get from the browser's geolocation api.

Bob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文