zip code to latitude and longitude

Can you show me where I can get a code to convert from zip code or address to get
latitude/longitude?

latitude/longitude is all I need to know. I know there is google xml that I can use. but need some helps to get latitude/longitude.

Thanks,
solution1368Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Use the Google Map api
e.g.
<script>
$.ajax({
url:"http://maps.googleapis.com/maps/api/geocode/xml?address=12345&sensor=false"
,success:function(data) {

alert($(data).find("location").find("lat").first().text())
alert($(data).find("location").find("lng").first().text())
}
});
</script>

Open in new window

Just pass in your zip code or address to the address part in the url

Working example
http://jsfiddle.net/GaryC123/nQFaZ/2/

Edited
Sometimes you get two lots of coordinates.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
solution1368Author Commented:
can you show me in c# asp.net? eventually, i would like to create as a wcf service.
0
GaryCommented:
I don't know, you asked this in JavaScript.
If you want a .net version you should probably post a separate question in that topic area.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I don't believe you will find this in any web scripting code.  The lat/lon for a polygon is based on the population centroid.   You would get this from the census.  However, it looks like due to the govt shutdown, it is not available.  http://www.census.gov/tiger/tms/gazetteer/zips.txt

There are plenty of sources to purchase data from if you are interested.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
With GIS mapping in the U.S. polygons are made from things like postal carrier routes, zip codes, block groups, counties, states, congressional districts and countries.

Postal carrier routes are a subset of zip codes and determined by the postal service.  Block Groups are a subset of Counties and are determined by the census.     Counties are typically larger areas then Zips(Postal Code) and Zips will typically not match up with counties.  Just as postal carrier routes will not match up with block groups. Actually postal carrier routes can be disjointed and are based on the traffic patterns of the carrier.

The Centroid of the polygon refers to the the population center.  Let's say you live in zip code 12345 and the zip code is a square with 10,000 homes. In the north east corner of the zip there is a lake.  Because of the lake, there is heavy population.  The west side of the zip is made up of multiple large parks and nature reserves with few residents.  

Because the population is heavier in the north east, you would see the lat/lon point for that zip polygon placed closer towards the north east.    A good way to think of this is a fulcrum.  If you are on a teeter toter with 3 people on one side and one on the other, the point where the teeter toter needs to be attached has to be closer to the 3 people in order for it to balance.

That "balance" point is the centroid or population centroid.  I think this point is determined by the U.S. Census.  When you see points on a map based on a zip or state, that is typically the population centroid.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Good solution.  You don't have to download your own data that way.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.