views:

2765

answers:

4

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

A: 

I don't think so. Running on a phone in the UK, the default map view still centres on Infinite Loop.

I try to avoid IB for this sort of thing and work with code.

Andiih
A: 

It DOES locate the user's current location, and it does ask for permission (though, like in all the other apps, I'm sure there's a default "Yes" that can be set). I'm almost 100% sure you can NOT set the zoom in IB. I'm sure it's programatically simple, but I'm (like you) waiting for Apple to give us some 411 on the MKMaps! But we can always just type and type until something works ;-)

Good luck!

Michael
+1  A: 

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 you programmatically change the user's location in the mapView. When using a device the co-ordinate should move to your GPS location.

ing0
A: 

In the simulator the CLLocationManager is hard coded to return a fix on Apple HQ. On a real device the CLLocationManager will return fixes from in order of accuracy, Skyhook Wireless, then Cell Mast triangulation, and finally the GPS subsystem. Note that on all devices not all are available. An iPod Touch can still return a location, but only from Skyhook Wireless (ie registered location of a Wireless AP)

The simulator only returns one location fix, if you want to see the location correct and zoom in on a real device you will need to register a CLLocationManagerDelegate when you set the user location flag on the MKMapView, and have the CLLocationManager startUpdatingLocation.

Use the received updates with code as above to set the center and span of the MKMapView to allow the map to center and zoom in on the location. It's probably best to set the span to something about the accuracy of the location fix you are provided which should allow you to see the whole blue ring of the GPS fix, providing useful feedback to the user.

Kevin