Java tutorial
//package com.java2s; import android.location.Location; import android.util.Log; public class Main { private static final String TAG = "TaxiUtil"; static final int LOCATIONTIME_THRESHOLD = 10000; public static Location chooseBetterLocation(Location location1, Location location2) { if (location1 != null) { Log.i(TAG, "Location1 : Lat: " + location1.getLatitude() + " Lng: " + location1.getLongitude()); } else { Log.d(TAG, "Location1 is null!"); return location2; } if (location2 != null) { Log.i(TAG, "Location2 : Lat: " + location2.getLatitude() + " Lng: " + location2.getLongitude()); } else { Log.d(TAG, "Location2 is null!"); return location1; } if (location1.getTime() > location2.getTime()) { return chooseTimeOrderedLocation(location1, location2); } else { return chooseTimeOrderedLocation(location2, location1); } } private static Location chooseTimeOrderedLocation(Location location1, Location location2) { if ((location1.getTime() - location2.getTime()) > LOCATIONTIME_THRESHOLD) { return location1; } else { return (location1.getAccuracy() > location2.getAccuracy()) ? location1 : location2; } } }