Reputation: 2291
I am a newbie with objective c style development. I have an android app which I am trying to convert into an iPhone app.
In the android app I have a LocationManager
, LocationListener
created, which onLocationChanged()
behaves the usual way to give me the updated location, as and when it changes.
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);
I have used the CLLocationManager
to generate location information in the ios app
self.locationManager = [[CLLocationManager alloc] init];
if ( [CLLocationManager locationServicesEnabled] ) {
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 100;
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[self.locationManager startUpdatingLocation];
}
how do I ensure that as and when the location changes this would be called and I would get the new location information. Of course at this point in time I am using the ios simulator and not the iphone hardware, but technically I would want this to work on the iphone too.
any suggestions ?
Upvotes: 1
Views: 1228
Reputation: 10621
You have to use CLLocationManager and the CLLocationManagerDelegate protocol. The class which implements CLLocationManagerDelegate gets the new location via method:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
Upvotes: 2