i need to get my current coordinates. i try next, but it is does not get result.
public class FragmentNear extends SherlockFragment implements
android.location.LocationListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
locationManager = (LocationManager) getActivity().getSystemService(
Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, this);
v = inflater.inflate(R.layout.fragment_near, null);
DownloadWebPageTask dw = new DownloadWebPageTask();
dw.execute("");
return v;
}
@Override
public void onLocationChanged(Location loc) {
if (showMFD == 0) {
Log.d("myLogs", "-------- onLoChanged " + myLat + " " + myLong);
myLat = loc.getLatitude();
myLong = loc.getLongitude();
Log.d("myLogs", "-------- onLoChangedEnd " + myLat + " " + myLong);
}
}
public void showMFD() {
showMFD++;
//my Tasks
}
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
Log.d("myLogs", "Background");
while (myLat==0)
{
}
showMFD();
return "";
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
pb = new ProgressDialog(getActivity());
pb.setMessage("Получение данных GPS...");
pb.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pb.show();
}
@Override
protected void onPostExecute(String result) {
pb.dismiss();
}
}
My logic is in the picture
An example of tracker class to use wifi or classic gps (3g, h+, gprs...)
It is as fast as the network/gps/phone (thanks android) you just need to create GPSTracker.java then an object :
In onDestroy() or when you don't want to use the gps anymore don't forget :