I am working on gps application that'll pick the users exact location but i can't do it in good way [closed]

StackOverflow https://stackoverflow.com/questions/21685035

  •  09-10-2022
  •  | 
  •  

문제

It take to me 7-14 minutes to pick the users exact location with gps.I tried is with gsm and network they are quick but not accurate like gps.But gps takes too much time to give me the exact location. And the other problem is i want i dialog box that'll appear and say user to "Please wait connecting to gps" but i don't know when to show this message and when to hide it but location Listener keep changing and all that stuff i am looking for good and practical answer.

Here is my code until now.

 public class FragmentAddPlace extends Fragment implements
    OnItemSelectedListener, OnClickListener, LocationListener {
@Override
public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    setUpLocationClientIfNeeded();
    Log.e("OnResume ", "Eroor");
    mLocationClient.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            5000, 15, this);

    mLocationClient.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER, 5000, 15, this);
}
@Override
public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    setUpLocationClientIfNeeded();
    Log.e("OnResume ", "Eroor");
    mLocationClient.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            5000, 15, this);

    mLocationClient.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER, 5000, 15, this);
}
LocationManager mLocationClient;

private void setUpLocationClientIfNeeded() {
    if (mLocationClient == null) {
        mLocationClient = (LocationManager) getActivity().getSystemService(
                Context.LOCATION_SERVICE); // OnConnectionFailedListener
    }
}

@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    loc = location;
    Log.e("OnLoactionChanged", "Location is Lattitude:" + loc.getLatitude()
            + " Longitude:" + loc.getLongitude() + " ");
    Toast.makeText(getActivity(), "Location is Updated", Toast.LENGTH_LONG)
            .show();
}

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub
    Toast.makeText(getActivity(), "Please Enable GPS provider",
            Toast.LENGTH_SHORT).show();
}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub
    mLocationClient.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            5000, 15, this);
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
    mLocationClient = (LocationManager) getActivity().getSystemService(
            Context.LOCATION_SERVICE);
    cd = new ConnectionDetector(getActivity());
    isInternetPresent = cd.isConnectingToInternet();
    if (savedInstanceState != null) imgbit =        savedInstanceState.getParcelable("image");
    init();
    Log.e("onActivity Created", "Eroor");
}

}

도움이 되었습니까?

해결책

You need free view to sky for GPS.
GPS does not work indoors (only near windows), so move up and go outside.
It will then receive a location ususally within 20-40s.

You can read out the estimated location accuracy:

Use Location.getHoricontalAccuracy() to get the location error in meters.
If the value is above 30m it is a bad GPS position.
You might show a warning in that case, or your "wait dialog".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top