I am using split view controller in my application. Left panel(Master View Controller) holds table view with list of hotels and on right, the Detail View Controller contains MapView for displaying the location. Initially I am displaying the current location upon application launch. Then after selecting a value from table view, I am trying to show the hotel location in the map. Unfortunately even upon passing proper latitude & longitude values, I am still not able to change the region and I don't see any change in the location at all.
Here is the implementation code snippet for understanding!!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *hotelInfo = [self.hotelDetails objectAtIndex:indexPath.row];
NSString *placeLatitude = [hotelInfo valueForKey:@"Latitude"];
NSString *placeLongitude = [hotelInfo valueForKey:@"Longitude"];
CLLocationCoordinate2D location;
location.latitude = [placeLatitude doubleValue];
location.longitude = [placeLongitude doubleValue];
[self setMapViewLocation:location];
}
-(void)setMapViewLocation:(CLLocationCoordinate2D)location
{
[[MapView sharedMapInstance] updateMapViewWithLocation:location];
}
Here is how I am utilising the location value for setting the region for MapView:
-(void)updateMapViewWithLocation:(CLLocationCoordinate2D)location
{
// [self.locationManager startUpdatingLocation];
// NSLog(@"latitude:%f,longitude:%f",location.latitude,location.longitude);
//
// MKCoordinateRegion region;
// region.center = location;
//
// MKCoordinateSpan span;
// span.latitudeDelta = 0.015;
// span.longitudeDelta = 0.015;
// region.span = span;
// NSLog(@"Center (%f, %f) span (%f, %f) user: (%f, %f)| IN!", region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta, location.latitude, location.longitude);
//
// [self.locationView setRegion:region animated:YES];
// MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 800, 800);
// MKCoordinateSpan span = {.latitudeDelta = 0.015, .longitudeDelta = 0.015};
MKCoordinateRegion region;
region.center = location;
[self.locationView setRegion:[self.locationView regionThatFits:region] animated:NO];
}
The commented lines are the various combinations of solutions I tried, but nothing seems to work.
Note: I am able to pass the coordinate values precisely as I found correct values in log.
Can someone please help me, thanks :)
MapView sharedMapInstancea singleton? Using a singleton here seems a bit strange. How doessharedMapInstancegive you a reference to the detail view controller of the UISplitViewController? - user467105[self.splitViewController.viewControllers objectAtIndex:1]should be the reference to the detail vc. But rather than accessing the detail vc directly this way, it might be better to use NSNotificationCenter or some other loosely-coupled approach. - user467105