Skip to content

Instantly share code, notes, and snippets.

@yuchen
Created July 27, 2013 13:25
Show Gist options
  • Save yuchen/6094861 to your computer and use it in GitHub Desktop.
Save yuchen/6094861 to your computer and use it in GitHub Desktop.
网上找的经纬度差距离计算
public class t {
public static void main ( String[] args ) {
double earthRadius = 6371; //地球半径,单位km
double lat1 = 31.215961;
double lng1 = 121.456083;
// 经纬度差0.000001
double lat2 = 31.215960;
double lng2 = 121.456082;
double dLat = Math.toRadians ( lat2 - lat1 );
double dLng = Math.toRadians ( lng2 - lng1 );
double a = Math.sin ( dLat / 2 ) * Math.sin ( dLat / 2 ) +
Math.cos ( Math.toRadians ( lat1 ) ) * Math.cos ( Math.toRadians ( lat2 ) ) *
Math.sin ( dLng / 2 ) * Math.sin ( dLng / 2 );
double c = 2 * Math.atan2 ( Math.sqrt ( a ), Math.sqrt ( 1 - a ) );
double dist = earthRadius * c;
int meterConversion = 1609;
System.out.println ( dist * 1000 ); // 距离!!!
System.out.print ( new Float ( dist * meterConversion ).floatValue() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment