Click here to Skip to main content
15,867,328 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
Hello,

How can I get nearest Zipodes on the basis of inputted zip code & miles/distance?

Ex. 07302 is the zip code for jersey city. So if I enter 07302 and distance is 10, then it should return other zip codes within 10 miles.

Thanks.

What I have tried:

I have tried with diff. codes and google API.
Posted
Updated 16-Dec-16 16:07pm
v2

You need a database containing the ZIP codes and the corresponding locations.

Then you can create a circle around a given position using the distance as radius and query the database for locations inside that circle.

But it would be much simpler to use a square. Then you just have to check for latitudes and longitudes inside the distance range.

You have to convert the distance in miles to latitude and longitude offsets:

1 degree latitude = 111.132 km
1 degree longitude = 111.320 km * cos(latitude)

While not precise, the above formulas can be used for short distances.
 
Share this answer
 
On earth, the formula to calculate the distance between 2 places is called great circle distance.
Great-circle distance - Wikipedia[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900