我一直在关注一些教程并创建一些简单的Android应用程序,但我遇到了一些问题,它只包括显示当前位置(经度,纬度,海拔高度)。
关于最新情况的任何想法?提前谢谢!
package com.ricard.location.app;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
TextView textLat;
TextView textLong;
TextView textAlt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textLat = (TextView) findViewById(R.id.textLat);
textLong = (TextView) findViewById(R.id.textLong);
textAlt = (TextView) findViewById(R.id.textAlt);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
class mylocationlistener implements LocationListener{
@Override
public void onLocationChanged(Location location){
if(location != null)
{
double plong = location.getLongitude();
double plat = location.getLatitude();
double palt = location.getAltitude();
textLat.setText(Double.toString(plat));
textLong.setText(Double.toString(plong));
textAlt.setText(Double.toString(palt));
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
}
}
答案 0 :(得分:0)
在此设备上接收到信号时出现错误,我在一台新设备上测试了它并且它有效,因此这是一个硬件错误。
谢谢!