我有下一个问题,我需要使用互联网获取坐标,但是当我连接到移动互联网(Edge)时,我在整个公寓中得到相同的坐标,当我使用 WI Fi 时坐标不同。我的代码是:
public class FetchCordinates extends AsyncTask<String, Integer, String> {
ProgressDialog progDailog = null;
public LocationManager mLocationManager;
public VeggsterLocationListener mVeggsterLocationListener;
@Override
protected void onPreExecute() {
mVeggsterLocationListener = new VeggsterLocationListener();
mLocationManager = (LocationManager) getActivity()
.getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 1000, 10,
mVeggsterLocationListener);
progDailog = new ProgressDialog(getActivity());
progDailog.setTitle("Получение координат");
progDailog
.setMessage("Получение Вашего местоположения, ожидайте, это может занять несколько минут...");
progDailog.setIndeterminate(true);
progDailog.setCancelable(false);
progDailog.setButton(DialogInterface.BUTTON_NEGATIVE, "Отмена",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FetchCordinates.this.cancel(true);
mLocationManager
.removeUpdates(mVeggsterLocationListener);
}
});
progDailog.show();
}
@Override
protected void onCancelled() {
Log.d("myLogs", "Cancelled by user!");
progDailog.dismiss();
}
@Override
protected void onPostExecute(String result) {
progDailog.dismiss();
if (myLat == 0) {
new AlertDialog.Builder(getActivity())
.setTitle("Ошибка получения координат")
.setMessage("Попробуйте позже...")
.setPositiveButton("Ок",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// continue with delete
}
}).show();
} else {
pg = new Progress();
pg.execute("");
}
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
long timeOfStartingThread = System.currentTimeMillis();
while (myLat == 0.0) {
if (System.currentTimeMillis() - timeOfStartingThread > timeToGetGps_ms) {
break;
}
}
mLocationManager.removeUpdates(mVeggsterLocationListener);
return null;
}
public class VeggsterLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
try {
myLat = location.getLatitude();
myLong = location.getLongitude();
Toast.makeText(
getActivity(),
" Координаты получены :" + myLat
+ ", :" + myLong,
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
}
}
@Override
public void onProviderDisabled(String provider) {
Log.d("myLogs", "OnProviderDisabled");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("myLogs", "onProviderEnabled");
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
Log.d("myLogs", "onStatusChanged");
}
}
}