Quote:
Originally Posted by Duncan C
I told you how to save the location. Create an instance variable (called something like currentCoordinate) in your map view delegate of type CLLocationCoordinate2D.
In your didUpdateToLocation method, save the newLocation.coordinate to currentCoordinate.
Finally, in your code that handles the button press, use currentCoordinate as the region center that you pass to setRegion.
Slow down, read the documentation on MKMapView and CLLocationManager, and look through some of the sample apps that come with XCode. It's very well documented, and there are a number of good examples apps included. It takes some time and study to understand how it works and how to use it.
You might want to download and try our company's location bookmarking app, Save My Place. (The iPhone version is only $0.99.) In our app, we have a checkbox that lets you ask to show your current location. When you check it, the app scrolls the map when the user's location gets too close to the edge of the map. It will also scroll the map to keep both your current location and your selected destination on-screen, if you ask to show both. We do all that by setting flags based on the state of "show location" and "show destination" checkboxes, and then deciding how to respond to location manager updates based on the state of the flags and the current map span.
|
Hi Duncan,
I've followed your instructions and created my instance variable, currentCoordinate (CLLocationCoordinate2D) inside my .h file.
@interface MapView : UIViewController
<CLLocationManagerDelegate, MKMapViewDelegate, MKReverseGeocoderDelegate>
{
IBOutlet UITextField *accuracyTextField;
IBOutlet UITextField *latitudeTextField;
IBOutlet UITextField *longitudeTextField;
CLLocationManager *lm;
CLLocationCoordinate2D currentCoordinate;
}
AND THEN, I save the newLocation.coordinate to currentCoordinate as you've stated.
- (void) locationManager

CLLocationManager *) manager
didUpdateToLocation

CLLocation *) newLocation
fromLocation

CLLocation *) oldLocation {
newLocation.coordinate = currentCoordinate;
AND LASTLY, I use the currentCoordinate as the newRegion.center, is that right?
-(IBAction) UserClickCLButton
{
MKCoordinateRegion newRegion;
newRegion.center = currentCoordinate;
newRegion.span.latitudeDelta = 0.23;
newRegion.span.longitudeDelta = 0.23;
[mapView setRegion:newRegion animated:YES];
}
BUT, it stills shows me and error stated :
newLocation.coordinate = currentCoordinatel -"object cannot be set - either readonly property or no setter found"