Iphone – MKMapView questions

iphoneiphone-sdk-3.0mapping

I've been working with the MKMapView control (SDK v3.0) in the simulator for a few days. I have been able to map an arbitrary location, zoom it, drop a pin, and add an annotation. I'm still a bit fuzzy on the full capabilities of the MKMapView control itself (outside of the simulator), however.

If the MKMapView's 'Shows User Location' property is checked, the iPhone simulator drops a pin on Apple's headquarters. Obviously, the simulator is not actually geocoding the phone's actual location.

Does this functionality imply, however, that the MKMapView has an instance of CLLocationManager 'in' it? Said another way, will the MKMapView, when the 'Shows User Location' option is selected, automatically find the phone's location and drop a pin? If so, does it do this without prompting for permission to get the location? Can I set the default zoom level in IB?

Thanks for your time,

Craig Buchanan

Best Answer

Here's an example of zooming programatically (there is no way in IB to do this):

   MKCoordinateRegion region;
   MKCoordinateSpan span;
   span.latitudeDelta=0.02 / 10; // zoom level
   span.longitudeDelta=0.02 / 10;

   CLLocationCoordinate2D location;
   location.latitude = latitude; // set these var's first!
   location.longitude = longitude;

   region.span=span;
   region.center=location;

   [mapView setRegion:region animated:TRUE];
   [mapView regionThatFits:region];

I'm not sure if this is what you're after but have you tried mapView.userLocation for the CLLocation stored?

Also remember that in the iPhone Simulator the pin will always drop on Apple HQ unless (from Xcode4) you change the simulated user's location - this is a Location Services arrow-icon just above the console in Xcode. When using a device the co-ordinate should move to your GPS location, depending on coverage.

Related Topic