返回信息流public class Gps extends Activity
{
TextView longitude;
TextView latitude;
Location location;
LocationManager locMan;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
longitude = (TextView) findViewById(R.id.longitude);
latitude = (TextView) findViewById(R.id.latitude);
Location mLocation = getLocation(this);
longitude.setText("longitude:" + mLocation.getLongitude());
latitude.setText("latitude:" + mLocation.getLatitude());
}
public Location getLocation(Context context)
{
//得到系统服务
String contextService = Context.LOCATION_SERVICE;
locMan = (LocationManager) getSystemService(contextService);
//GPS获得位置
String provider = LocationManager.GPS_PROVIDER;
location = locMan.getLastKnownLocation(provider);
return location;
}
}
模拟器总是显示应用程序错误,请重试。问题出在getLocation这了,但是改不明白了,logcat总是说是nullpointer的问题,不是很明白location的这些用法,望大牛解答~
这是一条镜像帖。来源:北邮人论坛 / java / #18012同步于 2011/4/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
android模拟器显示经纬度的问题
DevaMakaay
2011/4/25镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。