我目前仅使用GPS来获取用户的当前位置以返回特定结果。和比利时一样,如果你在里面,大部分时间你都无法获得GPS连接。所以我想通过wifi连接获得当前位置。使用GPS和WIFI获取当前位置
我发现这个例子:get the current location (gps/wifi) 但
我不知道这行告诉选择哪个连接的设备。我猜这是这个:String provider = myLocationManager.getBestProvider(criteria,true);
我必须添加到我的代码。
当我检查里面有什么,我总是得到一个空值,我不明白为什么。目前
我的代码如下所示:
public void getOwnLngLat(){
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
final LocationListener locationListener = new LocationListener(){
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
longitude="" + location.getLongitude();
latitude="" + location.getLatitude();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
};
locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), 2000, 10, locationListener);
}
你是什么意思的更新? (英语不是我的母语)我只想获得当前位置的经度和纬度。 我发现了另一个例子:http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in- an/3145655#3145655将执行此帮助我转发? – Hannelore 2011-05-06 08:17:55
位置提供者(例如GPS)会将位置更新(纬度,经度,时间,精度等)传递给您的LocationListener对象。这些更新在您调用requestLocationUpdates方法时开始,并且会定期继续,直到您调用removeUpdates方法。 – 2011-05-06 08:21:20