首页 新闻 会员 周边 捐助

google map定位问题

0
悬赏园豆:20 [待解决问题]

刚接触android,照着网上例子做了个定位的小程序,结果定不了位,帮忙看下什么问题

private GeoPoint getCurrentGeoPoint() {
GeoPoint p
=null;
LocationManager locationManager
= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
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);
Toast.makeText(
this,provider,Toast.LENGTH_LONG).show();
Location location
=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location ==null){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, locationListener );
location
=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
if(location==null){
p
=new GeoPoint((int)(23.129803*1e6),(int)(113.219218*1e6));
}
else
{
double lat=location.getLatitude();
double lng=location.getLongitude();
p
=new GeoPoint((int)(lat*1e6),(int)(lng*1e6));
}
return p;
}
private LocationListener locationListener =new LocationListener(){
//当坐标改变时触发此函数
publicvoid onLocationChanged(Location location){}
//Provider禁用时触发此函数,比如GPS被关闭
publicvoid onProviderDisabled(String provider) {}
//Provider启用时触发此函数,比如GPS被打开
publicvoid onProviderEnabled(String provider){}
//Provider的转态在可用、暂时不可用和无服务三个状态直接切换时触发此函数
publicvoid onStatusChanged(String provider,int status,Bundle extras){}
};
Beginning的主页 Beginning | 初学一级 | 园豆:180
提问于:2011-09-16 14:05
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册