Reputation: 11
I am having trouble when trying to use a MKMapView. This is my first time trying to use one of these and I haven't been able to figure out how to work it. Here are the two different pieces of sample code that I used to try to get it to work and neither work:
mapView = [[MKMapView alloc] initWithFrame:CGRectMake( 0, 0, 320, 150 )];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance( CLLocationCoordinate2DMake( latitude, longitude ), metersPerMile*0.5, metersPerMile*0.5 );
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:region];
[mapView setRegion:adjustedRegion];
or
mapView = [[MKMapView alloc] initWithFrame:CGRectMake( 0, 0, 320, 150 )];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance( CLLocationCoordinate2DMake( latitude, longitude ), metersPerMile*0.5, metersPerMile*0.5 );
[mapView setRegion:region];
or
mapView = [[MKMapView alloc] initWithFrame:CGRectMake( 0, 0, 320, 150 )];
[self.mapView setRegion:MKCoordinateRegionMake(CLLocationCoordinate2DMake( latitude, longitude ), MKCoordinateSpanMake( 0.01, 0.01 ))];
all of these snippets of code do absolutely nothing for the MKMapView. Whenever the view ends up loading, it doesn't do anything and I'm just left looking at all of North America, which isn't very helpful.
If anyone can help me out with this, I would greatly appreciate it.
Upvotes: 1
Views: 826
Reputation: 2600
If you are tying to load the MapView this will help
- (void)mapViewWillStartLoadingMap:(MKMapView *)mapView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSLog(@"map loading...");
}
Upvotes: 0
Reputation: 1240
I show the user where he is by implementing – mapView:viewForAnnotation: from MKMapViewDelegate. Take a look at this:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
// If it's the user location, return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
{
MKCoordinateSpan coordinateSpan = MKCoordinateSpanMake(0.009, 0.009);
[mapView setRegion:MKCoordinateRegionMake(annotation.coordinate, coordinateSpan) animated:YES];
}
return nil;
}
Upvotes: 0
Reputation: 39978
You haven't added map to your view.. like [self.view addSubView:mapView];
Upvotes: 1