问题
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