Introduced two frames, encoded as attributes, after initialization, after passing in a latitude and longitude, the display map:
#import <CoreLocation/CoreLocation.h>#import<MapKit/MapKit.h>@interface Ytmapapplecontroller () @property (nonatomic,strong) Clgeocoder*Geocoder, @end @implementation ytmapapplecontroller- (void) viewdidload {[Super viewdidload]; _geocoder=[[Clgeocoder alloc]init]; [Self location]; //Do any additional setup after loading the view.}-(void) location{[_geocoder reversegeocodelocation:[[cllocation alloc]initwithlatitude:39.0Longitude:116.0] completionhandler:^ (Nsarray<clplacemark *> * _nullable placemarks, Nserror *_nullable Error) {Clplacemark*clplacemark=[Placemarks Firstobject]; //locate landmarks and convert to a mapMkplacemark *mkplacemark=[[Mkplacemark Alloc]initwithplacemark:clplacemark]; Nsdictionary*options=@{mklaunchoptionsmaptypekey:@ (Mkmaptypestandard)}; Mkmapitem*mapitem=[[Mkmapitem Alloc]initwithplacemark:mkplacemark]; [Mapitem openinmapswithlaunchoptions:options]; }];}
Display the map according to the name of an address:
-(void) location{
[_geocoder geocodeaddressstring:@ "Beijing" completionhandler:^ (Nsarray *placemarks, Nserror *error) {
Get the first landmark
Clplacemark *clplacemark=[placemarks Firstobject];
Locate landmarks and convert to a map
Mkplacemark *mkplacemark=[[mkplacemark Alloc]initwithplacemark:clplacemark];
Nsdictionary *[email protected]{mklaunchoptionsmaptypekey:@ (Mkmaptypestandard)};
Mkmapitem *mapitem=[[mkmapitem Alloc]initwithplacemark:mkplacemark];
[Mapitem openinmapswithlaunchoptions:options];
}];
}
IOS22 Map Location-Apple bring your own map