2017-01-08 5 views
0

私は4つのLonLat点を持っています。私は4の中点を見つけたいと思います。 これを行うには、まず最初に2点を求め、次に2点目を見つけ、次に2つの最初の結果の中間点を見つけます。それは場所私はその一方で私は、何らかの理由で赤道上にある値を取得動作しませんhttps://stackoverflow.com/a/4656937/44896294 LonLat Androidの中間点を取得

Unforuntaly:私はこの記事で見つけたコードを使用し、私の点の間の中間点を見つけるには

中点を見つけようとするのは英国です。ここで

は私のコードです:

D/DEBUG: first locatoin lat: 52.954037691647834 long: 52.954037691647834 
D/DEBUG: second locatoin lat: 52.95385240191483 long: 52.95385240191483 

、ここでは、私は結果として得るものです::

D/DEBUG: midpoint lat 0.9242206929866051 midpoint long: 0.9242206929866051 

おかげでここ

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; 
    } 

は、私が入力環境い値であり、

答えて

1

これはちょうどwilですあなたはラジアンで結果を得ているようです。結果を度に換算すると52.9539448が得られます。これは正しいと思います。

+0

ありがとうございます! –

関連する問題