关于GPS的问题

T-Quake 2010-09-27 06:59:50
大家好,我最近在调关于GPS的东西,

我搞了个网上的代码 写了个测试程序

import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class CurrentLocation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(serviceName);
//String provider = LocationManager.GPS_PROVIDER;

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);

Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "纬度:" + lat + "\n经度:" + lng;
} else {
latLongString = "无法获取地理信息";
}
myLocationText.setText("您当前的位置是:\n" +
latLongString);
}
}


可是不知道为什么 怎么总是去调用A-GPS,并且去设置GPRS的东西,可是我不想去走GPRS的A-GPS,而是想走GPS.不知道 是不是接口调用的有问题.
...全文
218 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
T-Quake 2010-10-07
  • 打赏
  • 举报
回复
我想問下 我可不可以 發送模擬的GPS信號 如同在模擬器上的 一樣,手機內部有什麽命令可以發送這樣的命令嗎?模擬器是用geo ,手機上有什麽命令嗎?
文斌 2010-09-29
  • 打赏
  • 举报
回复
可能是机器驱动默认就是先走AGPS
T-Quake 2010-09-29
  • 打赏
  • 举报
回复
不行,还是走A-gps 而且发现代码中的listener根本一直没被触发,location一直是空值
yangji842003 2010-09-29
  • 打赏
  • 举报
回复
使用系统提供的provider试试看:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10,
locationListener);
T-Quake 2010-09-29
  • 打赏
  • 举报
回复
发现 编译成.so的驱动程序 报Log.e()的错误, 不停的去reset on off gps芯片
T-Quake 2010-09-29
  • 打赏
  • 举报
回复
E/gps_sirf( 1149): SIRF_PAL_HW_WriteRESET, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): rtn V O 0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteRESET, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteRESET, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteRESET, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteRESET, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=1
E/gps_sirf( 1149): SIRF_PAL_HW_WriteON_OFF, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteRESET, level=0
E/gps_sirf( 1149): SIRF_PAL_HW_WriteRESET, level=1
E/gps_sirf( 1149): rtn V C 0
yangji842003 2010-09-28
  • 打赏
  • 举报
回复
可能是这句话的问题
criteria.setAccuracy(Criteria.ACCURACY_FINE);
不应该用精确定位,因为精确定位是用AGPS,可以考虑使用模糊定位,模糊定位才是使用GPS。
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
T-Quake 2010-09-28
  • 打赏
  • 举报
回复
是真机器.发现驱动走A-gps,会配置GPRS,然后将值传给驱动,驱动进入冷启动状态.然后onLocationChanged
就没被执行过.去读串口发现gps已经启动,并且不停的写数据,可是为什么onLocationChanged
没执行呢?
dinjay 2010-09-28
  • 打赏
  • 举报
回复
真机还是模拟器,查看下设备的GPS设置是否正确

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧