best way to get the latitude and longitude values of a zip code - C#

北城余情 提交于 2019-12-13 03:47:57

问题


What is the best way to get the latitude and longitude values of a zip code?

This is the function that I am currently using, but it only allows 2400 requests per 24 hours.

private Coordinates GetZipCoordinates(string zip)
    {
        string address = "";
        address = "http://maps.googleapis.com/maps/api/geocode/xml?components=postal_code:" + zip.Trim() + "&sensor=false";

        var result = new System.Net.WebClient().DownloadString(address);
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(result);
        XmlNodeList parentNode = doc.GetElementsByTagName("location");
        var lat = "";
        var lng = "";
        foreach (XmlNode childrenNode in parentNode)
        {
        lat = childrenNode.SelectSingleNode("lat").InnerText;
        lng = childrenNode.SelectSingleNode("lng").InnerText;
        }

        return new Coordinates(Convert.ToDouble(lat), Convert.ToDouble(lng));
    }

Is there a better way to do it? I would like to avoid the request limit. Please suggest. Thanks.


回答1:


You can download a free zipcode database here:

http://federalgovernmentzipcodes.us/

Use your own and you don't have to make any remote calls.




回答2:


@Lance - That is the question of the day, "How often does zipcode data actually change?" First, remember that a zipcode does not respect any political boundaries (they can span counties and states) because a zipcode is merely a delivery area, designed for the convenience of the US Postal Service and zipcodes change at the whim of the USPS. Any time they want to realign boundaries or merge one zipcode into another (or any other change to a delivery area) will be a change to the zipcode data. Creation or retirement of a zipcode (happens every month) will also mean a change to the data.

So, depending on your data needs, you may want to have data that is updated monthly. Here is the data from Aug2015.

If you need an API for zipcodes, here are a few:

  • zippopotam.us
  • smartystreets.com (I work here)
  • zipcodeapi.com
  • zipfeeder.us


来源:https://stackoverflow.com/questions/30620666/best-way-to-get-the-latitude-and-longitude-values-of-a-zip-code-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!