14,334,458 members
Rate this:
See more: , +
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:

## 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:

## Solution 2

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