diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-01 11:04:34 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-01 11:04:34 +0000 |
commit | 41d73bf90e2e94c91df8a865d54d5cb23b9101c9 (patch) | |
tree | 3c80345d9a699a8d60d2a03e37f69e0f98fac676 /EssentialsGeoIP/src/com/maxmind/geoip/Location.java | |
parent | ec18c0096d91f237a27e9aa88a96857403b2ed40 (diff) | |
download | Essentials-41d73bf90e2e94c91df8a865d54d5cb23b9101c9.tar Essentials-41d73bf90e2e94c91df8a865d54d5cb23b9101c9.tar.gz Essentials-41d73bf90e2e94c91df8a865d54d5cb23b9101c9.tar.lz Essentials-41d73bf90e2e94c91df8a865d54d5cb23b9101c9.tar.xz Essentials-41d73bf90e2e94c91df8a865d54d5cb23b9101c9.zip |
EssentialsGeoIP is now officially part of Essentials
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1292 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsGeoIP/src/com/maxmind/geoip/Location.java')
-rw-r--r-- | EssentialsGeoIP/src/com/maxmind/geoip/Location.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/EssentialsGeoIP/src/com/maxmind/geoip/Location.java b/EssentialsGeoIP/src/com/maxmind/geoip/Location.java new file mode 100644 index 000000000..040fcb6b1 --- /dev/null +++ b/EssentialsGeoIP/src/com/maxmind/geoip/Location.java @@ -0,0 +1,60 @@ +/** + * Location.java + * + * Copyright (C) 2004 MaxMind LLC. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Lesser Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package com.maxmind.geoip; + +public class Location { + public String countryCode; + public String countryName; + public String region; + public String city; + public String postalCode; + public float latitude; + public float longitude; + public int dma_code; + public int area_code; + public int metro_code; + + private final static double EARTH_DIAMETER = 2 * 6378.2; + private final static double PI = 3.14159265; + private final static double RAD_CONVERT = PI / 180; + + public double distance (Location loc) { + double delta_lat, delta_lon; + double temp; + + float lat1 = latitude; + float lon1 = longitude; + float lat2 = loc.latitude; + float lon2 = loc.longitude; + + // convert degrees to radians + lat1 *= RAD_CONVERT; + lat2 *= RAD_CONVERT; + + // find the deltas + delta_lat = lat2 - lat1; + delta_lon = (lon2 - lon1) * RAD_CONVERT; + + // Find the great circle distance + temp = Math.pow(Math.sin(delta_lat/2),2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(delta_lon/2),2); + return EARTH_DIAMETER * Math.atan2(Math.sqrt(temp),Math.sqrt(1-temp)); + } +} |