下面是我写的一个函数
private Boolean getLocationInfo()
{
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 100, 1, new LocationListener(){ @Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
if(arg0 != null)
{
map.this.la = arg0.getLatitude();
map.this.lo = arg0.getLongitude();
}
} @Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
} @Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
} @Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}}); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location == null)
{
f.ShowToast(map.this, "NETWORK_PROVIDER");
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if(location != null)
{
this.la = location.getLatitude();
this.lo = location.getLongitude();
return true;
}
else
return false;
}遇到一些问题,请教一下大家
1.gps定位不行,都是用的NETWORK(我程序里在走network的时候会有提示)
2.我用手机里的自带的googlemap来定位,就算定位不到,也会定一段时间,而我的程序好像是gps一定位失败马上就用network了,这个延迟函数应该怎么写?
3.network定位很不准确,隔了好几条马路,而同样是手机自带的googlemap的定位在关闭gps后定位基本也是准确的,它是怎么实现的?谢谢各位
private Boolean getLocationInfo()
{
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 100, 1, new LocationListener(){ @Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
if(arg0 != null)
{
map.this.la = arg0.getLatitude();
map.this.lo = arg0.getLongitude();
}
} @Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
} @Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
} @Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}}); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location == null)
{
f.ShowToast(map.this, "NETWORK_PROVIDER");
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if(location != null)
{
this.la = location.getLatitude();
this.lo = location.getLongitude();
return true;
}
else
return false;
}遇到一些问题,请教一下大家
1.gps定位不行,都是用的NETWORK(我程序里在走network的时候会有提示)
2.我用手机里的自带的googlemap来定位,就算定位不到,也会定一段时间,而我的程序好像是gps一定位失败马上就用network了,这个延迟函数应该怎么写?
3.network定位很不准确,隔了好几条马路,而同样是手机自带的googlemap的定位在关闭gps后定位基本也是准确的,它是怎么实现的?谢谢各位
至于你说的“googlemap来定位,就算定位不到,也会定一段时间”,我想可能是上次定位成功过,可能googlemap保存了你当时的经纬度,当gps不可以用时,googlemap会从数据库中读。
这是我的理解,我觉得这是可行的。
开启一个gps service,通过位置侦听,只要gps定位成功,就发一个广播给你,你在处理。
在不能开启gps服务的时候用network来定位。
如果都不行,通过读数据库的历史文件来显示你的路经信息。我想也只能这样了另外我用真机在真机定位时,gps不可用,但是我走不同方向的时候它的箭头还会在变,我就感觉很奇怪,明明gps不可用,为什么箭头会变,要知道,通过network来定位,位置是不变的,因为无线路由的位置就放那,不可能变的。
大家一起讨论讨论吧
你能把此例子发一份给我email吗 [email protected] thanks