我是android開發新手。在過去的幾個月中,我構建了一個現在可以運行的應用程序現在我想要改善每次打開應用程序時所有打擾我的小事情。Android GPS數據不顯示
在這種情況下,我嘗試獲取GPS(僅GPS)位置。每當位置更新進入時,都應該顯示。
出於任何原因,第一個職位(我可以看到他們進入調試日誌中)被忽略並且不會顯示在我的設備上。
下面是代碼:
public class GpsLogging extends Activity{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gps_logging);
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
}
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
double lat = loc.getLatitude();
double lon = loc.getLongitude();
float accuracy = loc.getAccuracy();
TextView textView = (TextView) findViewById(R.id.gpsPosition);
textView.setText("My current location is: \n" +
"Latitude = " + lat +"\n"+
"Longitude = " + lon +"\n"+
"Accuracy = " + accuracy +" m");
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
將是很好,如果有人有一個想法,爲什麼unprecise數據被忽略。
這裏是相應的XML的要求:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.example.GpsLogging">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gpsPosition"
android:text="Aquiring GPS Position"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
帖子佈局xml也... –
您的設備有GPS激活?檢查 – LXSoft
「我可以看到他們進入調試日誌」: - 您在哪裏編寫日誌的打印語句。 –