开发者

Formatting City/State Information

开发者 https://www.devze.com 2023-02-05 15:00 出处:网络
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 for

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 thi开发者_如何学编程s 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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号