私は緯度と経度を検索するためのコードを試していますが、座標を与えるのに時間がかかったり、全く座標が与えられていません。サムスンギャラクシータブで自分のコードを試しています。 アンドロイドGPSデバイスがその緯度と経度を取得するのにかかる時間
LocationManager mlocManager;
double lat,lng;
LocationListener mlocListener = new MyLocationListener();
は、私は()メソッドのonCreateで以下のコードを呼び出す
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
リスナーMyLocationListenerクラスコードは下回っている問題、任意のポインタをすることができたり、私が考慮されていない何
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc){
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " + "Latitude = " + loc.getLatitude() + "Longitude = " + loc.getLongitude();
String latLongString = "";
if (loc != null) {
lat = loc.getLatitude();
lng = loc.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
TextView myLocationText = (TextView)findViewById(R.id.FindUsTextView);
myLocationText.setText("Your Current Position is:\n" + latLongString);
System.out.println(latLongString);
}
/* findUsProgressbarField.setVisibility(View.INVISIBLE);*/
Toast.makeText(FindUs.this, Text, Toast.LENGTH_SHORT).show();
mlocManager.removeUpdates(mlocListener);
}
@Override
public void onProviderDisabled(String provider){
Toast.makeText(getApplicationContext(),"Gps Disabled, Please Enable the GPS", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider){
Toast.makeText(getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mlocManager != null) {
mlocManager.removeUpdates(mlocListener);
mlocManager = null;
}
}
いくつかの点。 あなたの返事を楽しみにしています。ありがとう。
「設計通り」のように聞こえます。 Co ordsは常に利用可能なわけではありません。そして、それらを最初に得ることは高価です(時間内に)。 –