0
다음 문제가 있습니다. 인터넷을 사용하여 좌표를 가져올 필요가 있지만 Wi-Fi 좌표를 사용할 때 모바일 인터넷 (에지)과 연결할 때 내 평면이 동일한 평면으로 나타납니다. 다르다. 는 GPS가 불행히도, 기본적으로 매우 안정와이파이 또는 모바일 네트워크를 사용하여 GPS 좌표 가져 오기
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");
}
}
}
좋아, 나는 당신이 꼼꼼한 것. –