当前位置: 首页>>代码示例>>Java>>正文


Java Location.distanceBetween方法代码示例

本文整理汇总了Java中android.location.Location.distanceBetween方法的典型用法代码示例。如果您正苦于以下问题:Java Location.distanceBetween方法的具体用法?Java Location.distanceBetween怎么用?Java Location.distanceBetween使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.location.Location的用法示例。


在下文中一共展示了Location.distanceBetween方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDistanceBetween

import android.location.Location; //导入方法依赖的package包/类
public static Double getDistanceBetween(LatLon latLon1, LatLon latLon2) {
    if (latLon1 == null || latLon2 == null)
        return null;
    float[] result = new float[1];
    Location.distanceBetween(latLon1.getLatitude(), latLon1.getLongitude(),
            latLon2.getLatitude(), latLon2.getLongitude(), result);
    return (double) result[0];
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:9,代码来源:LocationUtils.java

示例2: getLastIndexRed

import android.location.Location; //导入方法依赖的package包/类
private static int getLastIndexRed(ArrayList<LatLng> pointsGreen,ArrayList<LatLng> newPointsRed, int greenIndex) {
    int lastIndex = 0;
    double latitudeGreen = pointsGreen.get(0).latitude;
    double longitudeGreen = pointsGreen.get(0).longitude;
    double latitudeRed = newPointsRed.get(0).latitude;
    double longitudeRed = newPointsRed.get(0).longitude;
    float[] distance1 = new float[2];
    float[] distance2 = new float[2];

    Location.distanceBetween(latitudeGreen, longitudeGreen, latitudeRed, longitudeRed, distance1);

    for (LatLng latLng : newPointsRed) {
        latitudeRed = latLng.latitude;
        longitudeRed = latLng.longitude;
        Location.distanceBetween(latitudeGreen, longitudeGreen, latitudeRed, longitudeRed, distance2);
        if (distance1[0] >= distance2[0]) {
            distance1[0] = distance2[0];
            lastIndex = newPointsRed.indexOf(latLng);
        }
    }

    return lastIndex;
}
 
开发者ID:kav0rka,项目名称:VennTracker,代码行数:24,代码来源:Circles.java

示例3: reverseIfNeeded

import android.location.Location; //导入方法依赖的package包/类
private static ArrayList<LatLng> reverseIfNeeded(ArrayList<LatLng> checkAgainst, ArrayList<LatLng> listToReverse) {
    if (checkAgainst.size() < 2 || listToReverse.size() < 2) {
        return listToReverse;
    }
    float[] distance1 = new float[2];
    float[] distance2 = new float[2];
    LatLng toCheckLast = checkAgainst.get(checkAgainst.size() - 1);
    LatLng toReverseLast = listToReverse.get(listToReverse.size() - 1);
    LatLng toReverseFirst = listToReverse.get(0);
    Location.distanceBetween(toCheckLast.latitude, toCheckLast.longitude, toReverseLast.latitude,
            toReverseLast.longitude, distance1);
    Location.distanceBetween(toCheckLast.latitude, toCheckLast.longitude, toReverseFirst.latitude, toReverseFirst.longitude, distance2);
    if (distance1[0] < distance2[0]) {
        Collections.reverse(listToReverse);
    }
    return listToReverse;
}
 
开发者ID:kav0rka,项目名称:VennTracker,代码行数:18,代码来源:Circles.java

示例4: a

import android.location.Location; //导入方法依赖的package包/类
public final void a(double d, double d2, a aVar) {
    this.i = aVar;
    if (!(this.g == 0.0d || this.h == 0.0d)) {
        float[] fArr = new float[10];
        Location.distanceBetween(d, d2, this.c, this.d, fArr);
        if (fArr[0] < 1500.0f) {
            this.i.a(this.g + d, this.h + d2);
            return;
        }
    }
    if (!this.k) {
        this.a = "{\"source\":101,\"access_token\":\"160e7bd42dec9428721034e0146fc6dd\",\"location\":{\"latitude\":" + d + ",\"longitude\":" + d2 + "}\t}";
        this.e = d;
        this.f = d2;
        this.j = new b(this);
        this.j.start();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:b.java

示例5: calcDistance

import android.location.Location; //导入方法依赖的package包/类
private double calcDistance(Location location) {
    float distance = 0;
    float[] distanceArr = new float[2];
    if (location != null) {
        Location.distanceBetween(
                prevLatitude,
                prevLongitude,
                location.getLatitude(),
                location.getLongitude(), distanceArr);
        if (ValidateUtil.isValidNumber(distanceArr[0])) {
            distance = distanceArr[0];
        }
    }
    Log.d(TAG, "calcDistance : distance= " + distance);
    return distance;
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:17,代码来源:GPSDetector.java

示例6: getNearestTo

import android.location.Location; //导入方法依赖的package包/类
/**
 * This method provides the Camera out of the list that is nearest to the given location
 * @param latitude latitude of the location
 * @param longitude longitude of the location
 * @param cameras a list of cameras out of which the nearest will be returned
 * @return the camera nearest to the location
 */
public static Camera getNearestTo(double latitude, double longitude, Set<Camera> cameras)
{
    float[] result = new float[3];

    float distance = Float.MAX_VALUE;
    Camera nearest = null;

    for (Camera camera : cameras) {
        Location.distanceBetween(latitude, longitude, camera.getLatitude(), camera.getLongitude(), result);

        if (result[0] < distance) {
            distance = result[0];
            nearest = camera;
        }
    }

    return nearest;
}
 
开发者ID:Jugendhackt,项目名称:Camera-warner,代码行数:26,代码来源:LocationUtils.java

示例7: simplifyIntersections

import android.location.Location; //导入方法依赖的package包/类
private static ArrayList<LatLng> simplifyIntersections(ArrayList<LatLng> intersections) {
    // If the size is 1, no need to check anything
    if (intersections.size() > 1) {
        // Loop from the end so we can remove a without an error
        for (int a = intersections.size() - 1; a > 0; a--) {
            for (int b = 0; b < intersections.size(); b++) {
                // don't check itself
                if (a == b) {
                    continue;
                }
                // Get the distance between the 2 points
                float[] distanceIntersections = new float[2];
                Location.distanceBetween(
                        intersections.get(a).latitude,
                        intersections.get(a).longitude,
                        intersections.get(b).latitude,
                        intersections.get(b).longitude,
                        distanceIntersections);
                // Our margin of error is 20 meters
                //This isn't perfect but it will get us a close enough solution
                if (distanceIntersections[0] < 20) {
                    // Too close, remove it
                    intersections.remove(a);
                    if (intersections.size() > 1) {
                        // Recursivly remove locations
                        return simplifyIntersections(intersections);
                    }
                }
            }
        }
    }
    return intersections;
}
 
开发者ID:kav0rka,项目名称:VennTracker,代码行数:34,代码来源:Circles.java

示例8: distanceBetween

import android.location.Location; //导入方法依赖的package包/类
/**
 * Returns the distance between two locations in m
 * @param latitude1 latitude of the 1st location
 * @param longitude1 longitude of the 1st location
 * @param latitude2 latitude of the 2nd location
 * @param longitude2 longitude of the 2nd location
 * @return the distance between the locations in m
 */
public static float distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2)
{
    float[] result = new float[3];

    Location.distanceBetween(latitude1, longitude1, latitude2, longitude2, result);

    return result[0];
}
 
开发者ID:Jugendhackt,项目名称:Camera-warner,代码行数:17,代码来源:LocationUtils.java

示例9: GetDistance

import android.location.Location; //导入方法依赖的package包/类
public static float GetDistance(GeoPoint point1, GeoPoint point2)
{
    float[] results = new float[10];
    Location.distanceBetween(
            point1.getLatitude(),
            point1.getLongitude(),
            point2.getLatitude(),
            point2.getLongitude(),
            results);

    // ToDo: check, is that always results[0]?
    return results[0];
}
 
开发者ID:LenaShervarly,项目名称:TreasureHunting,代码行数:14,代码来源:LocationHelper.java

示例10: MaxDistanceForRoute

import android.location.Location; //导入方法依赖的package包/类
public static double MaxDistanceForRoute(String szRoute) {
    double dist = 0.0;
    float[] rgDistResults = new float[1];

    if (szRoute == null || szRoute.length() == 0)
        return dist;

    Airport[] rgAp = Airport.AirportsFromRoute(szRoute, null);

    int cAirports = rgAp.length;

    for (int i = 0; i < cAirports; i++) {
        Airport ap1 = rgAp[i];

        if (ap1 == null || !ap1.IsPort())
            continue;

        for (int j = i + 1; j < cAirports; j++) {
            Airport ap2 = rgAp[j];

            if (!ap2.IsPort())
                continue;

            Location.distanceBetween(ap1.Latitude, ap1.Longitude, ap2.Latitude, ap2.Longitude, rgDistResults);
            double d = rgDistResults[0] * MFBConstants.METERS_TO_NM;
            if (d > dist)
                dist = d;
        }
    }

    return dist;
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:33,代码来源:Airport.java

示例11: checkDistance

import android.location.Location; //导入方法依赖的package包/类
/**
 * Check distance between current location and this locations
 * @param latLng location compared to current location
 * @param range distance to filter events by
 * @return true if within range; false otherwise
 */
public boolean checkDistance(LatLng latLng, Double range) {
    lastLocation = getDeviceLoc();
    float results[] = new float[10];
    Location.distanceBetween(lastLocation.getLatitude(), lastLocation.getLongitude(),
            latLng.latitude, latLng.longitude, results);
    if (results[0] <= range) {
        return true;
    } else {
        return false;
    }
}
 
开发者ID:CMPUT301F17T23,项目名称:routineKeen,代码行数:18,代码来源:MapFilter.java

示例12: getTrackSummary

import android.location.Location; //导入方法依赖的package包/类
/**
 * Get track summary
 *
 * @return TrackSummary object
 */
TrackSummary getTrackSummary() {
    Cursor positions = db.query(DbContract.Positions.TABLE_NAME,
            new String[] {"*"},
            null, null, null, null,
            DbContract.Positions._ID);
    double startLon, startLat, endLon, endLat;
    long startTime, endTime;
    long distance = 0;
    TrackSummary summary = null;
    if (positions.moveToFirst()) {
        long count = 1;
        startLon = positions.getDouble(positions.getColumnIndex(DbContract.Positions.COLUMN_LONGITUDE));
        startLat = positions.getDouble(positions.getColumnIndex(DbContract.Positions.COLUMN_LATITUDE));
        startTime = positions.getLong(positions.getColumnIndex(DbContract.Positions.COLUMN_TIME));
        endTime = startTime;
        while (positions.moveToNext()) {
            count++;
            endLon = positions.getDouble(positions.getColumnIndex(DbContract.Positions.COLUMN_LONGITUDE));
            endLat = positions.getDouble(positions.getColumnIndex(DbContract.Positions.COLUMN_LATITUDE));
            endTime = positions.getLong(positions.getColumnIndex(DbContract.Positions.COLUMN_TIME));
            float[] results = new float[1];
            Location.distanceBetween(startLat, startLon, endLat, endLon, results);
            distance += results[0];
            startLon = endLon;
            startLat = endLat;
        }
        long duration = endTime - startTime;
        summary = new TrackSummary(distance, duration, count);
    }
    positions.close();
    return summary;
}
 
开发者ID:bfabiszewski,项目名称:ulogger-android,代码行数:38,代码来源:DbAccess.java

示例13: calcDistance

import android.location.Location; //导入方法依赖的package包/类
private double calcDistance(double latitude, double longitude) {
    float distance = 0;
    float[] distanceArr = new float[2];
    if (curLatitude >= 0 && curLongitude >= 0) {
        Location.distanceBetween(
        curLatitude, curLongitude,
        latitude, longitude, distanceArr);
    }
    if (ValidateUtil.isValidNumber(distanceArr[0])) {
        distance = distanceArr[0];
    }
    return distance;
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:14,代码来源:GeoTagTracker.java

示例14: getDistance

import android.location.Location; //导入方法依赖的package包/类
void getDistance() {
        float[] results = new float[3];
        // 距離を計算 ///////////////////////////
        // results[0] : 距離(メートル)
        //        [1] : 始点から終点までの方位角
        //        [2] : 終点から始点までの方位角
        Location.distanceBetween( myLocationData.lat, myLocationData.lon,
                                    oppLocationData.lat, oppLocationData.lon, results);
//        Location.distanceBetween( lat, lon, 36.56815810607431, 140.6476289042621, results);
//        Log.d( "DISTANCE", "distance`getDistance = " + results[0] );

        if( results[1] < 0 ) {
            // 0~360度の値にする
            results[1] = 360f + results[1];
        }

        // 円グラフを回転
        RADER_VALUES.invalidateLocation( results[1], results[0] );

        // 距離メッセージ変更
        textView_distanceAR.setText( (int)results[0] + "m");
        if( results[0] <= 20 ) textView_DistanceMessage.setText("近いよ");
        else if( results[0] == 0 ) textView_DistanceMessage.setText("やばいよ");
        else textView_DistanceMessage.setText("遠いよ");

        // 精度メッセージ変更
        if( oppLocationData.acc <= 3 ) textView_AccuracyMessage.setText("精度良好かも");
        else if( oppLocationData.acc > 3 && oppLocationData.acc <= 10 ) textView_AccuracyMessage.setText("ふつうの精度");
        else if ( oppLocationData.acc >= 15 ) textView_AccuracyMessage.setText("精度ひどいよ");
//        else if ( data.acc >= 15 ) textView_AccuracyMessage.setText("不安な精度");
        else textView_AccuracyMessage.setText( "" );



        ////////////////////////////////////////////////////////////////////////////////////////////
        // 位置情報取得頻度を変化させる ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////
        if ( results[0] <= RADER_VALUES.MAX_DISTANCE ) { // レーダー圏内/圏外で1秒/5秒を変化
            locationProvider.setLocationUpdateMinTime( true );
        } else {
            locationProvider.setLocationUpdateMinTime( false );
        }
        ////////////////////////////////////////////////////////////////////////////////////////////


        // デバッグ用にデータを表示したいんじゃよ
        // 表示形式を設定
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy'年'MM'月'dd'日' kk'時'mm'分'ss'秒'");

        String stringInfo = "【 自分( "+ myID + " ) 】\n" +
                "lat : " + myLocationData.lat + "\n" +
                "lon : " + myLocationData.lon + "\n" +
                "acc : " + myLocationData.acc + "\n" +
                "【 相手( "+ oppID + " ) 】\n" +
                "lat : " + oppLocationData.lat + "\n" +
                "lon : " + oppLocationData.lon + "\n" +
                "acc : " + oppLocationData.acc + "\n" +
                "\n"+
                "【 距離 】 " + results[0] + "m\n" +
                "【 自 → 相 】 " + results[1] + "\n" +
                "【 相 → 自 】 " + results[2] + "\n" +
                "【 取得時刻 】\n" +
                "(自)" + sdf.format( new Date( myLocationData.gettime ) ) + "\n" +
                "(相)" + sdf.format( new Date( oppLocationData.gettime ) );

        Log.d("Location", myLocationData.gettime + " " + oppLocationData.gettime );
        textView_info.setText( stringInfo );

        if( results[0] <= 40 && flag_vibrator == true ) {
            // ここでバイブレーション///////////////////////////////////////////
            // 振動
            viberation( results[0] );
        }

    }
 
开发者ID:jphacks,项目名称:TK_1701,代码行数:76,代码来源:RaderActivity.java

示例15: distanceBox

import android.location.Location; //导入方法依赖的package包/类
public void distanceBox(){
    Location.distanceBetween(originLat,originLong,
            destLat,destlong, dist);
}
 
开发者ID:thandomy,项目名称:foodie,代码行数:5,代码来源:MapElements.java


注:本文中的android.location.Location.distanceBetween方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。