格式化城市/州信息
我有一个存储用户的家乡、州和国家的应用程序。我并不特别需要进行验证;应用程序的其他部分不依赖于数据,但我希望格式保持一致,以实现虚荣心,并避免以后在数据库中出现“北卡罗来纳州”、“北卡罗来纳州”、“北卡罗来纳州”等。
有谁知道一种方法来传递 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我可能已经找到了解决方案:
GeocodeServiceRequest.ReverseGeocodeRequest
方法(位于 MSDN)返回一个具有Address
成员的GeocodeResponse
类。这又具有按照我想要的方式形成地址所需的所有属性。因此,将有一个带有 Action 的控制器来获取地址的字符串形式,它将发送回格式正确的版本。我将尝试这个并在几个小时内更新代码。它不完全是客户端,这不是最理想的,但看起来它会工作得很好。
I think I may have found the solution: The
GeocodeServiceRequest.ReverseGeocodeRequest
method (on MSDN) returns aGeocodeResponse
class which has anAddress
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.
我怀疑您需要执行以下操作:
如果你像这样分解它,你可能想播种你的#1使用从浏览器的地理定位 API 获取的 lat/lng。
鲍勃
I suspect that you will need to do the following:
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