How to make the user wait a long time to get the location fix?

I am creating an Android GPS application that gets the closest locations based on the user's current location.

This is what my application does:

  • Check if GPS or network is available.
  • If not, do nothing. Otherwise, we first check the availability of GPS, if it is there, if not, then we check the network.
  • After using one of them, we get the current location and then send it to the server.
  • As soon as we retrieve data from the server and update the user interface, we stop listening to further updates to the location. Once is enough until they press the update button, which starts it again.

What I hope to do:

  • If the GPS or network cannot get the location, for example, 2 minutes, then we switch suppliers. We do not want the user to wait too long.

  • It would be nice to be able to use both providers and then get the most accurate from them. I looked at http://developer.android.com/guide/topics/location/strategies.html and I saw the isBetterLocation method. How to integrate this method into my application? I am having trouble understanding how, where and when to call it. I assume that isBetterLocation () requires me to simultaneously call the network and GPS. It would be nice if my application listened to them as accuracy. How should I do it? What if one of them is unavailable?

Here is part of my code:

if(!GPSEnabled && !networkEnabled)
{
    Toast.makeText(this, "Error: This application requires a GPS or network connection",
            Toast.LENGTH_SHORT).show();
}
else
{
    if(GPSEnabled)
    {
        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }
    else if(networkEnabled)
    {
        System.out.println("Getting updates from network provider");
        locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    }
}

onLocationChanged. lat/lng, , .

public void onLocationChanged(Location location)
{
    //Get coordinates
    double lat = (location.getLatitude());
    double lng = (location.getLongitude());
    Log.d("MainActivity", "got location: " + lat + ": " + lng);
    //get nearest locations
    new GetLocations().execute(SharedVariables.root + SharedVariables.locationsController + SharedVariables.getNearestMethod + lat + "/" + lng); 

    // Zoom in, animating the camera after the markers have been placed
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 10));
    System.out.println("lat = " + lat + ", lng = " + lng);

     //Stop listening for updates. We only want to do this once. 
     locManager.removeUpdates(this);
}
+5
1

GPS , , .

:

  • GPS , , GPS - ( 3 ). , /, . GPS , , . .

  • , - : . / ; , , . GPS , .

, . , .

GPS, , , GPS- . :

  • ,
  • ,

GPS , , 2 , . , .

: ; , API android .

0

All Articles