## 如何计算android中两个纬度和经度点之间的距离？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (38)

• Android位置提供商
• 数学计算

### 2 个回答

``````Location locationA = new Location("point A");
locationA.setLatitude(latA);
locationA.setLongitude(lngA);
Location locationB = new Location("point B");
locationB.setLatitude(latB);
LocationB.setLongitude(lngB);
distance = locationA.distanceTo(locationB) ;
``````

``````LatLng latLngA = new LatLng(12.3456789,98.7654321);
LatLng latLngB = new LatLng(98.7654321,12.3456789);

Location locationA = new Location("point A");
locationA.setLatitude(latLngA.latitude);
locationA.setLongitude(latLngA.longitude);
Location locationB = new Location("point B");
locationB.setLatitude(latLngB.latitude);
locationB.setLongitude(latLngB.longitude);

double distance = locationA.distanceTo(locationB);
``````

``````public double CalculationByDistance(double initialLat, double initialLong,
double finalLat, double finalLong){
int R = 6371; // km
double dLat = toRadians(finalLat-initialLat);
double dLon = toRadians(finalLong-initialLong);