public class MainActivity extends Activity implements VIEw.OnClickListener{//Defining vIEwsprivate EditText editTextLatitude;private EditText editTextLongitude;private EditText editTextTimeInserted;LocationManager lm;TextVIEw lt,ln;String provIDer;Location l;private button buttonAdd;private button buttonVIEw;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); //Initializing vIEws editTextLatitude = (EditText) findVIEwByID(R.ID.editTextLat); editTextLongitude = (EditText) findVIEwByID(R.ID.editTextLon); editTextTimeInserted = (EditText) findVIEwByID(R.ID.editTextTimeInserted); buttonAdd = (button) findVIEwByID(R.ID.buttonAdd); buttonVIEw = (button) findVIEwByID(R.ID.buttonVIEw); //Setting Listeners to button buttonAdd.setonClickListener(this); buttonVIEw.setonClickListener(this); ln = (TextVIEw) findVIEwByID(R.ID.lng); lt = (TextVIEw) findVIEwByID(R.ID.lat); lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria c = new Criteria(); provIDer = lm.getBestProvIDer(c,false); l = lm.getLastKNownLocation(provIDer); if (l != null) { //get latitude and longitude of the location double lng = l.getLongitude(); double lat = l.getLatitude(); //display on text vIEw ln.setText("" + lng); lt.setText("" + lat); } else { ln.setText("No ProvIDer"); lt.setText("No ProvIDer"); }}解决方法 让你的活动实现LocationListener
implements LocationListener
然后在onCreate中请求locationUpdates
lm.requestLocationUpdates(provIDer,20000,this);
然后在你的onLocationChanged方法中,为了实现LocationListener而覆盖,一旦发送位置就更新textVIEws
@OverrIDepublic voID onLocationChanged(Location location) { double lng = location.getLongitude(); double lat = location.getLatitude(); //display on text vIEw ln.setText("" + lng); lt.setText("" + lat); }总结
以上是内存溢出为你收集整理的Android应用程序在textViews中显示lat long全部内容,希望文章能够帮你解决Android应用程序在textViews中显示lat long所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)