获取到GPS数据,但是GPS数据一直保持不变。这是为何 做了个获取GPS的小demo,循环取GPS的数据,发现每次取经纬度和时间都是一样 不知为何,请教各位高手了。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 确信你的GPS位置更新了吗?可以在模拟器里模拟位置改变的,否则,都是最后一次的定位信息 是用模拟器测试还是真机测试?模拟器无法测实际经纬度的,只能靠手动输入进去的固定值。真机的话,检查一下代码,看看是不是事件监听没有做。同时LOG出来看一下。 打开gps了吗?有时显示是打开,但未真正的起作用。 locationManager.requestLocationUpdates(provider, 1000, 0, new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { updateToNewLocation(null); } @Override public void onLocationChanged(Location location) { updateToNewLocation(location);//更新GPS } }); } private void updateToNewLocation(Location location) { TextView tv; String text; tv = (TextView) findViewById(R.id.textv); if (location != null) { lat = location.getLatitude(); lon= location.getLongitude(); text="纬度:"+lat+"\n经度:"+lon; } else { text="无法获取地理信息"; } tv.setText(text); } public class GpsManager implements GpsStatus.Listener, LocationListener { private static Context context; private static GpsListener call; private List<GpsSatellite> numSatelliteList = new ArrayList<GpsSatellite>(); // 卫星信号 private static GpsManager mGpsListener; public void RegisteListener(Context _context, GpsListener _call){ context = _context; call = _call; getLocation(); } LocationManager locationManager; private void getLocation() { // 获取位置管理服务 String serviceName = Context.LOCATION_SERVICE; locationManager = (LocationManager) context .getSystemService(serviceName); // 获取GPS信息 String provider = LocationManager.GPS_PROVIDER; Location location = locationManager.getLastKnownLocation(provider);// 通过GPS获取位置 if (location == null) location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // updateToNewLocation(location); // 设置监听器,自动更新的最小时间为间隔N秒(1秒为1*1000)或最小位移变化超过N米 locationManager.requestLocationUpdates(provider, 1000, 0, this); locationManager.addGpsStatusListener(this); // 注册状态信息回调 } private void updateToNewLocation(Location location) { // 获取系统时间 Time t = new Time(); t.setToNow(); // 取得系统时间 int year = t.year; int month = t.month + 1; int date = t.monthDay; int hour = t.hour; // 24小时制 int minute = t.minute; int second = t.second; if (location != null) { double latitude = location.getLatitude();// 经度 double longitude = location.getLongitude();// 纬度 double altitude = location.getAltitude(); // 海拔 call.SetSatellite("搜索卫星个数:" + numSatelliteList.size()); call.SetLocation(new GPSPoint(longitude, latitude, 0, 0, 0, 0, GPSPoint.TYPE_CART)); call.SetLatestUpdateTime("/n时间:" + year + "年" + month + "月" + date + "日" + hour + ":" + minute + ":" + second); } else { call.SetSatellite("无法获取地理信息"); } } public void onLocationChanged(Location location) { // 当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发 if (location != null) { updateToNewLocation(location); } } public void onProviderDisabled(String provider) { // Provider被disable时触发此函数,比如GPS被关闭 updateToNewLocation(null); } public void onProviderEnabled(String provider) { // Provider被enable时触发此函数,比如GPS被打开 } public void onStatusChanged(String provider, int status, Bundle extras) { // Provider的转态在可用、暂时不可用和无服务三个状态直接切换时触发此函数 } @Override public void onGpsStatusChanged(int event) { GpsStatus status = locationManager.getGpsStatus(null); // 取当前状态 updateGpsStatus(event, status); } private void updateGpsStatus(int event, GpsStatus status) { if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) { int maxSatellites = status.getMaxSatellites(); Iterator<GpsSatellite> it = status.getSatellites().iterator(); numSatelliteList.clear(); int count = 0; while (it.hasNext() && count <= maxSatellites) { GpsSatellite s = it.next(); numSatelliteList.add(s); count++; } } } public interface GpsListener { // public void RegisteCallback(); public void SetLocation(GPSPoint point); public void SetSatellite(String numberInfo); public void SetLatestUpdateTime(String time); }} 请问关于Android系统下如何使用浏览器运行java的applet问题 图片旋转的算法 Android2.2有没有类似OPhone的DataConnection? Ophone API 提供个? android 前辈们帮我看看这个异步加载图片哪里错了? 请教几个开发时的问题。 onClick事件和onTouch事件共存问题 安卓是不是可以盗链任何网上的图片? android端将手机相册里的照片上传到服务器,照片在的内存扩大几倍,是怎么回事? 怎么找到安卓中程序闪退的原因 如何知道一个String 是一个有效的URL 地址。 gallery设置显示item个数
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
updateToNewLocation(null);
}
@Override
public void onLocationChanged(Location location) {
updateToNewLocation(location);//更新GPS
}
});
}
private void updateToNewLocation(Location location) {
TextView tv;
String text;
tv = (TextView) findViewById(R.id.textv);
if (location != null) {
lat = location.getLatitude();
lon= location.getLongitude();
text="纬度:"+lat+"\n经度:"+lon;
}
else {
text="无法获取地理信息";
}
tv.setText(text);
}
public class GpsManager implements GpsStatus.Listener, LocationListener { private static Context context;
private static GpsListener call;
private List<GpsSatellite> numSatelliteList = new ArrayList<GpsSatellite>(); // 卫星信号
private static GpsManager mGpsListener;
public void RegisteListener(Context _context, GpsListener _call){
context = _context; call = _call;
getLocation();
} LocationManager locationManager; private void getLocation() {
// 获取位置管理服务
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager) context
.getSystemService(serviceName);
// 获取GPS信息
String provider = LocationManager.GPS_PROVIDER; Location location = locationManager.getLastKnownLocation(provider);// 通过GPS获取位置 if (location == null)
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // updateToNewLocation(location);
// 设置监听器,自动更新的最小时间为间隔N秒(1秒为1*1000)或最小位移变化超过N米
locationManager.requestLocationUpdates(provider, 1000, 0, this);
locationManager.addGpsStatusListener(this); // 注册状态信息回调
} private void updateToNewLocation(Location location) {
// 获取系统时间
Time t = new Time();
t.setToNow(); // 取得系统时间
int year = t.year;
int month = t.month + 1;
int date = t.monthDay;
int hour = t.hour; // 24小时制
int minute = t.minute;
int second = t.second; if (location != null) {
double latitude = location.getLatitude();// 经度
double longitude = location.getLongitude();// 纬度
double altitude = location.getAltitude(); // 海拔 call.SetSatellite("搜索卫星个数:" + numSatelliteList.size());
call.SetLocation(new GPSPoint(longitude, latitude, 0, 0, 0, 0, GPSPoint.TYPE_CART));
call.SetLatestUpdateTime("/n时间:" + year + "年" + month + "月" + date + "日"
+ hour + ":" + minute + ":" + second);
} else { call.SetSatellite("无法获取地理信息");
}
} public void onLocationChanged(Location location) {
// 当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发
if (location != null) {
updateToNewLocation(location); }
} public void onProviderDisabled(String provider) {
// Provider被disable时触发此函数,比如GPS被关闭
updateToNewLocation(null);
} public void onProviderEnabled(String provider) {
// Provider被enable时触发此函数,比如GPS被打开
} public void onStatusChanged(String provider, int status, Bundle extras) {
// Provider的转态在可用、暂时不可用和无服务三个状态直接切换时触发此函数
} @Override
public void onGpsStatusChanged(int event) {
GpsStatus status = locationManager.getGpsStatus(null); // 取当前状态
updateGpsStatus(event, status);
} private void updateGpsStatus(int event, GpsStatus status) {
if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
int maxSatellites = status.getMaxSatellites();
Iterator<GpsSatellite> it = status.getSatellites().iterator();
numSatelliteList.clear();
int count = 0;
while (it.hasNext() && count <= maxSatellites) {
GpsSatellite s = it.next();
numSatelliteList.add(s);
count++;
}
}
} public interface GpsListener { // public void RegisteCallback();
public void SetLocation(GPSPoint point); public void SetSatellite(String numberInfo);
public void SetLatestUpdateTime(String time); }
}