Android 相当于LocationManager。目标c中的onLocationChanged
我是一个c风格开发的新手。我有一个android应用程序,我正试图将其转换为iPhone应用程序 在android应用程序中,我创建了一个Android 相当于LocationManager。目标c中的onLocationChanged,android,ios,iphone,cllocationmanager,Android,Ios,Iphone,Cllocationmanager,我是一个c风格开发的新手。我有一个android应用程序,我正试图将其转换为iPhone应用程序 在android应用程序中,我创建了一个LocationManager,LocationListener,它的onLocationChanged()行为与通常的方式一样,可以在位置发生变化时为我提供更新的位置 LocationManager locationManager = (LocationManager) this .getSystemService(Context.L
LocationManager
,LocationListener
,它的onLocationChanged()
行为与通常的方式一样,可以在位置发生变化时为我提供更新的位置
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
// some logic here
}
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, minTimeInterval, 0,
locationListener);
我已使用CLLocationManager
在ios应用程序中生成位置信息
self.locationManager = [[CLLocationManager alloc] init];
if ( [CLLocationManager locationServicesEnabled] ) {
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 100;
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[self.locationManager startUpdatingLocation];
}
我如何确保在位置更改时调用此命令,并获取新的位置信息。当然,现在我使用的是ios模拟器,而不是iphone硬件,但从技术上讲,我希望这也能在iphone上使用
有什么建议吗 您必须使用和协议。实现CLLocationManagerDelegate的类通过以下方法获取新位置:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
-(void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation