Can we use the 'post notification' for location updates to plot current location on google maps?? Or any better way to implement other than this ? Although i wish not to use KVO for @"Mylocations" in googlemaps.
In LocationTracker.m
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
for(int i=0;i<locations.count;i++)
{
CLLocation * newLocation = [locations objectAtIndex:i];
CLLocationCoordinate2D theLocation = newLocation.coordinate;
CLLocationAccuracy theAccuracy = newLocation.horizontalAccuracy;
[PlacesDetails sharedInstance].theLocation=theLocation;
if(newLocation != nil && (!(theLocation.latitude == 0.0 && theLocation.longitude == 0.0)))
{
self.myLastLocation = theLocation;
self.myLastLocationAccuracy= theAccuracy;
// Below implemented the post notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateLocation" object:nil];
}
}
}
In ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateGMSCameraPostition) name:@"updateLocation"
object:nil];
}
-(void)updateGMSCameraPostition
{
NSLog(@"CALLED UPDATELOCATION OBSERVER");
mapView_.camera = [GMSCameraPosition cameraWithTarget:[PlacesDetails sharedInstance].theLocation
zoom:14];}
Keban, That depends mainly how you have designed your app. You can use different pattern for this.
For blocks you can have a look over these links.
I think it might help you.