私はボタンクリックで経度と緯度による位置情報を取得するAndroidアプリを製作しました。Android GPSが正確になるまでに時間がかかります
まず最初に私はアプリケーションをロードして/ gpsをオンにすると不正確な引数のために最後の既知の位置の読み取り値を取得します。
私が知りたいのは、トーストメッセージ「場所を待っている」を取得したときに、Googleマップのように正確であるのを待つ方法です。
コードを改善する方法がある場合は、それも役立ちます。参照用
コード:読書のための
public class Clue extends Activity {
public static double latitude;
public static double longitude;
Criteria criteria;
LocationManager lm;
LocationListener ll;
Location location;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questions);
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
ll = new MyLocationListener();
lm.requestLocationUpdates(lm.getBestProvider(criteria, true), 0, 0, ll);
}
private boolean weAreThere() {
location = getLocation();
longitude = location.getLongitude();
latitude = location.getLatitude();
return inCorrectPlace(param);
}
private Location getLocation() {
lm.requestLocationUpdates(lm.getBestProvider(criteria, true), 0, 0, ll);
return lm.getLastKnownLocation(lm.getBestProvider(criteria, true));
}
}
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
Clue.longitude = loc.getLongitude();
Clue.latitude = loc.getLatitude();
}
}
おかげで、すべての返信は理解されるであろう。
ベンは
最高のプロバイダとは対照的に、すべてのプロバイダを使用する多分考えていましたか?それは超正確でなければならない。 –