Use the CLLocationManager class, MKMapView. And implement <MKMapViewDelegate, CLLocationManagerDelegate>
// Initialize CLLocationManager and CLLocationManager to obtain the current geographic coordinate
Locmanager = [[CLLocationManager alloc] init];
[Locmanager setDelegate: self];
// Set the accuracy
[Locmanager setDesiredAccuracy: kCLLocationAccuracyBest];
[Locmanager startUpdatingLocation];
After execution, the proxy method is automatically called:
In the proxy method:
-(Void) locationManager :( CLLocationManager *) manager didUpdateToLocation :( CLLocation *) newLocation fromLocation :( CLLocation *) oldLocation {
// Initialize the rectangle size
CGRect rect = CGRectMake (0, 0, 320,460 );
// Set the map size to the rectangle size
Map = [[MKMapView alloc] initWithFrame: rect];
CLLocationCoordinate2D loc = [newLocation coordinate];
Lat = loc. latitude;
Lon = loc. longpolling;
// Coordinate
CLLocationCoordinate2D theCoordinate;
CLLocationCoordinate2D theCenter;
// TheCoordinate. latitude = lat;
// TheCoordinate. longpolling = lon;
TheCoordinate = loc;
[Map setDelegate: self];
// Set the map display type, including satellite maps, roads, etc.
[Map setMapType: MKMapTypeStandard];
// [Map setMapType: MKMapTypeSatellite];
// Region coordinate Region (Region, Region)
MKCoordinateRegion theRegin;
// TheCenter. latitude = lat;
// TheCenter. longpolling = lon;
TheCenter = loc;
TheRegin. center = theCenter;
// Coordinate spacing (span: interval, spacing)
MKCoordinateSpan theSpan;
TheSpan. latitudeDelta = 0.1;
TheSpan. longitudeDelta = 0.1;
// Set the area displayed on the map,
TheRegin. span = theSpan;
// [Map setRegion: theRegin];
[Map regionThatFits: theRegin];
Map. showsUserLocation = YES;
[Self. view addSubview: map];
}
-(MKAnnotationView *) mapView :( MKMapView *) mapView viewForAnnotation :( id <MKAnnotation>) annotation {
NSLog (@ "------- viewForAnnotation -------");
// This class can display icons with the same needle
MKPinAnnotationView * newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation: annotationreuseIdentifier: @ "annotation1"];
// NewAnnotation. animatesDrop = YES;
// NewAnnotation. animatesDrop = NO;
NewAnnotation. pinColor = MKPinAnnotationColorPurple;
// Display flag prompt
NewAnnotation. canShowCallout = YES;
Return newAnnotation;
}