我有4个LonLat积分,我想找到4点的中点。 为了做到这一点,我把前2个发现了中点,然后第2个发现了这个点,然后找到了2个第一个结果之间的中点。
为了找到我的观点之间的中点,我使用了这篇文章中的代码:https://stackoverflow.com/a/4656937/4489629
Unforuntaly它不起作用我因某种原因得到赤道上的值,而我试图找到中点的位置在英国。
这是我的代码:
private void ItemPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ListBoxItem lbi = sender as ListBoxItem;
e.Handled = lbi.IsSelected;
}
以下是我输入的值:
private void treatForDispaly(double averageSpeed, double averageElevation, RecordObject[] records) {
String currentDateTimeString = String.valueOf(new java.util.Date());
LatLng firstTwo = midPoint(records[0].getLatitude(), records[0].getLongitude(), records[1].getLatitude(), records[1].getLongitude());
// LatLng seconTwo = midPoint(records[2].getLatitude(), records[2].getLongitude(), records[3].getLatitude(), records[3].getLongitude());
// LatLng averageLatLng = midPoint(firstTwo.latitude, firstTwo.longitude, seconTwo.latitude, seconTwo.longitude);
ContentValues newValues = new ContentValues();
newValues.put(ContentProviderContract.DAILY_RECORDS_TREATED_DATETIME,currentDateTimeString);
newValues.put(ContentProviderContract.DAILY_RECORDS_TREATED_ALTITUDE, averageElevation);
newValues.put(ContentProviderContract.DAILY_RECORDS_TREATED_SPEED, averageSpeed);
newValues.put(ContentProviderContract.DAILY_RECORDS_TREATED_LATITUDE, records[0].getLatitude()); // firstTwo.latitude
newValues.put(ContentProviderContract.DAILY_RECORDS_TREATED_LONGITUDE, records[0].getLongitude()); //firstTwo.longitude
getApplicationContext().getContentResolver().insert(ContentProviderContract.DAILY_RECORDS_TREATED_URI, newValues);
RecordTreatedObject tempRecord = new RecordTreatedObject();
tempRecord.setDateTime(new Date(currentDateTimeString));
tempRecord.setElevation(averageElevation);
tempRecord.setLatitude(firstTwo.latitude);
tempRecord.setLongitude(firstTwo.longitude);
tempRecord.setSpeed(averageSpeed);
dailyRecordsTreated.add(tempRecord);
}
public static LatLng midPoint(double lat1,double lon1,double lat2,double lon2){
double dLon = Math.toRadians(lon2 - lon1);
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
lon1 = Math.toRadians(lon1);
double Bx = Math.cos(lat2) * Math.cos(dLon);
double By = Math.cos(lat2) * Math.sin(dLon);
double lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
//return out in degrees
LatLng midpoint = new LatLng(lat3, lon3);
return midpoint;
}
以下是我得到的结果:
D/DEBUG: first locatoin lat: 52.954037691647834 long: 52.954037691647834
D/DEBUG: second locatoin lat: 52.95385240191483 long: 52.95385240191483
由于
答案 0 :(得分:1)
这只是一个疯狂的猜测,但似乎是你得到弧度的结果。将结果转换回度数,你得到52.9539448这是我认为的正确。