我是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
“我可以看到他们进入调试日志”: - 您在哪里编写日志的打印语句。 –