#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0

    Getting accurate GPS latitude and longitude


    So I'm trying to get the most accurate location. It seems to be giving me a location about 2 miles away where I was yesterday.

    Does anybody know how you can get about getting the phone to re calibrate where it is? The corresponding code is below.

    Obviously there there is no defensive code yet.

    Thank you in advance

    Code:
    public String getZipcode(){
    		Location location = getMyLocation();
    		double lat = location.getLatitude();
    		double lng = location.getLongitude();
    		List<Address> result = null;
    		Address thisAddress = null;
    		String zipcode = null;
    		Geocoder g = new Geocoder(this,Locale.getDefault());
    		try{
    			result = g.getFromLocation(lat, lng, 1);
    			thisAddress = result.get(i);
    			zipcode = thisAddress.getPostalCode();
    			}
    		}catch(Exception e){}
    		return zipcode;
    	}
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    What is getMyLocation() doing?

    From a quick read of the API it looks like you should be binding a callback to a LocationManager and using that to obtain regular updates on the current location (which you might already be doing, I can't tell). My guess is that there is not a specific call you make to ask for a recalibration; either the recalibration happens automatically in all cases, or it only happens when you have an active handler bound to a LocationManager.

    Another, perhaps more likely, possibility is that your LocationManager is set to only use GPS for location data and your phone is currently unable to obtain a GPS signal (for example, if you're testing inside a building). In that case the phone would probably return the last-known GPS location even if it differs from the phone's current location (as calculated using other metrics).
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0
    My apologies. I forgot I threw that method in there. It is

    Code:
    private Location getMyLocation() {
    		LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    		return lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    	}
    So looking at that, it still should get where I am especially since the GPS works fine for me and pinpoints where I am.

    After trudging through the API, you're right there is no re calibrate but at the same time, if it is getting a GPS signal, it should grab where it is now.

    Do you think maybe it's just that fickle?

IMN logo majestic logo threadwatch logo seochat tools logo