Geo Location API and user search in radius

I have a Java application and would like to know the location of the visitor. The API will provide me with a visitor’s zip code, and then based on this zip code, I will find the request fire and get users in my application within a radius of 25/50 miles. Alternatively, the visitor can enter the zip code of their interest, and the app should return users with a radius of six miles. For users registered in the system, we only have their zip code. I looked through some options, but did not find the exact solution. I do not want to download and maintain a zip code database. I do not think the Google API supports such things.

+2
source share
2 answers

I could not find any service offering an API. After much research, I found that you have to load the zip codes along with their latitude and longitude position into the table. then calculate the coordinates in the radius you want to find. This is a site that has helped me a lot. http://www.dougv.com/2009/03/27/getting-all-zip-codes-in-a-given-radius-from-a-known-point-zip-code-via-php-and- mysql /

Here is the calculation in java if you really want, if you don't want to work with php

// you get this by querying the database for the zip code Double latitude = Double.parseDouble (zipCode.getLatitude ()); Double longitude = Double.parseDouble (zipCode.getLongitude ());

Double latN =Math.asin( Math.sin(Math.toRadians(latitude)) * Math.cos(distance/radius) + Math.cos(Math.toRadians(latitude)) * Math.sin(distance/radius) * Math.cos(Math.toRadians(0))); Double latS =Math.asin( Math.sin(Math.toRadians(latitude)) * Math.cos(distance/radius) + Math.cos(Math.toRadians(latitude)) * Math.sin(distance/radius) * Math.cos(Math.toRadians(180))); Double longE = Math.toRadians(longitude) + Math.atan2( Math.sin(Math.toRadians(90)) * Math.sin(distance/radius)* Math.cos(Math.toRadians(latitude)) , Math.cos(Math.toRadians(distance/radius)) - Math.sin(Math.toRadians(latitude))* Math.sin(Math.toRadians(latN)) ); Double longW = Math.toRadians(longitude) + Math.atan2( Math.sin(Math.toRadians(270)) * Math.sin(distance/radius)* Math.cos(Math.toRadians(latitude)) , Math.cos(Math.toRadians(distance/radius)) - Math.sin(Math.toRadians(latitude))* Math.sin(Math.toRadians(latN)) ); System.out.println("Latutude N "+Math.toDegrees(latN) +" Latitide S "+Math.toDegrees(latS) +">>> Longitude E "+Math.toDegrees(longE) +" Longitude W "+Math.toDegrees(longW)); 
+2
source

I don’t know how accurate this is, but have you looked at IPinfoDB ? They will return XML and JSON results, but you will need to register for the API key. However, it doesn’t provide anything for the sake of it, but for nearby zipcodes you can use something like this: http://www.geonames.org/export/web-services.html#findNearbyPostalCodes

+2
source

All Articles