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
[Locmanagersetdesiredaccuracy: kcllocationaccuracybest];
[Locmanagerstartupdatinglocation];
After execution, the proxy method is automatically called:
In the proxy method:
-(Void) locationmanager :( cllocationmanager *) managerdidupdatetolocation :( 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];
Cllocationcoordinate2dloc = [newlocation coordinate];
Lat = LOC. Latitude;
Lon = LOC. longpolling;
// Coordinate Coordinate
Cllocationcoordinate2dthecoordinate;
Cllocationcoordinate2dthecenter;
// Thecoordinate. Latitude = Lat;
// Thecoordinate. longpolling = Lon;
Thecoordinate = LOC;
[MAP setdelegate: Self];
// Set the map display type, including satellite maps, roads, etc.
[MAP setmaptype: mkmaptypestandard];
// [Mapsetmaptype: mkmaptypesatellite];
// Region coordinate region (region, Region)
Mkcoordinateregiontheregin;
// Thecenter. Latitude = Lat;
// Thecenter. longpolling = Lon;
Thecenter = LOC;
Theregin. Center = thecenter;
// Coordinate spacing (span: interval, spacing)
Mkcoordinatespanthespan;
Thespan. latitudedelta = 0.1;
Thespan. longitudedelta = 0.1;
// Set the area displayed on the map,
Theregin. span = thespan;
// [Mapsetregion: theregin];
[Mapregionthatfits: theregin];
Map. showsuserlocation = yes;
[Self. viewaddsubview: map];
}
-(Mkannotationview *) mapview :( mkmapview *) mapviewforannotation :( id <mkannotation>) annotation {
Nslog (@ "------- viewforannotation -------");
// This class can display icons with the same needle
Mkpinannotationview * newannotation = [[mkpinannotationviewalloc] initwithannotation: annotationreuseidentifier: @ "annotation1"];
// Newannotation. animatesdrop = yes;
// Newannotation. animatesdrop = no;
Newannotation. pincolor = mkpinannotationcolorpurple;
// Display flag prompt
Newannotation. canshowcallout = yes;
Return newannotation;
}