【发布时间】:2014-07-07 18:03:42
【问题描述】:
我一直在学习一些教程并创建了一些简单的 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) {
}
}
}
【问题讨论】:
-
“我遇到了一些麻烦”。你遇到了什么问题?
-
你想做什么? GPS 只为您提供 gps 坐标(纬度、经度)。看到这个 - stackoverflow.com/a/3145655/713778
-
GPS 还提供海拔高度@ranjk89。更多的是他面临什么问题?应用程序会崩溃吗?他有堆栈跟踪吗?
-
对第一个帖子很抱歉,哈哈,
-
问题是我没有得到任何错误,但是一旦我在我的设备上测试它,我什么也得不到,只是空的文本标签。
标签: android gps geolocation