Created
November 28, 2013 10:14
-
-
Save muyiou/7689781 to your computer and use it in GitHub Desktop.
解决国产手机Location.distancTo()距离不准的问题
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static final double EARTH_RADIUS = 6378137; | |
| private static double rad(double d) | |
| { | |
| return d * Math.PI / 180.0; | |
| } | |
| public static double getDistanceofPoint(Location locationA, Location locationB) { | |
| double radLat1 = rad(locationA.getLatitude()); | |
| double radLat2 = rad(locationB.getLatitude()); | |
| double a = radLat1 - radLat2; | |
| double b = rad(locationA.getLongitude()) - rad(locationB.getLongitude()); | |
| double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) + | |
| Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2))); | |
| s = s * EARTH_RADIUS; | |
| s = Math.round(s * 10000) / 10000; | |
| return s; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment