Search code examples
javaandroidgeolocationgps

Methods for giving best estimate of Location from three Android location providers


After reading this older post, Good way of getting the user's location in Android , I wondered if anyone has any theories on how to solve this problem for finding the best estimate of location. Obviously GPS would be ideal but assume for a second it gives a bad measure every so often.

Lets say I get the three measures, GPS, WIFI, and Cell Tower with their degrees of accuracy, what methods might you suggest to find the "best" location?

My initial reaction would be to do some type of weighted centroid function where I have three points and assign weights to all three for accuracy and then find the closest point to the three points with their given accuracies. My other thought is to use machine learning but that seems really excessive unless I'm specifically making something to solve this problem. Thoughts? This is mostly based on me wondering how Skyhook solves the problem using the data.


Solution

  • //declare constants
    
     // The minimum distance to change Updates in meters
    private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 20; // 10 meters
    
     // The minimum time between updates in milliseconds
    private static final long MIN_TIME_BW_UPDATES = 2000 * 60 * 1; // 1 minute
    
    public void getlocation() 
    {  
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    
       // Define the criteria how to select the locatioin provider        
        Criteria criteria = new Criteria();
        provider = locationManager.getBestProvider(criteria, false);
        locationManager.requestLocationUpdates(provider, MIN_TIME_BW_UPDATES,
                      MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
    
        if (locationManager != null) {
        Location location = locationManager.getLastKnownLocation(provider);
    
           if (location != null) {
              loclat = location.getLatitude();
              loclong = location.getLongitude();                                
           }
       }
    }