This is a better mechanism to find distance between two IPs. It is faster than using Haversine formula as discussed in my previous post because this is faster than getting latitude and longitude and computing the distance.
import com.maxmind.geoip.Location;
import com.maxmind.geoip.LookupService;
import java.io.IOException;
public class GeoDistanceTwoIPs {
public static void main(String args[]) throws Exception {
//args[0] is the geolite.dat .......... args[1] is ip1 args[2] is ip2
LookupService lookupService = new LookupService(args[0]);
Location location1 = lookupService.getLocation(args[1]);
Location location2 = lookupService.getLocation(args[2]);
System.out.print("Distance: " + location1.distance(location2) + " kilometers");
}
}
Comments
Leave a comment Trackback