Click here to Skip to main content
14,334,458 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

On earth, the formula to calculate the distance between 2 places is called great circle distance.
Great-circle distance - Wikipedia[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100