One, the effect chart.
Second, engineering drawings.
Three, code.
ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "MapLocation.h"
@ Interface Viewcontroller:uiviewcontroller
<MKMapViewDelegate>
{
mkmapview *_mapview;
NSString *addressstring;
}
Viewcontroller.m
#import "ViewController.h" @interface Viewcontroller () @end @implementation Viewcontroller-(void) Viewdidload {[sup
ER viewdidload];
Do no additional setup after loading the view.
Call the system's own gold map//show the current location of the offline map _mapview = [[Mkmapview alloc] init];
_mapview.frame = CGRectMake (0, 40, 320,400);
_mapview.delegate = self;
_mapview.maptype = Mkmaptypestandard;
[Self.view Addsubview:_mapview];
addressstring=@ "Light Kai City";
NSLog (@ "---addressstring---%@", addressstring);
[Self geocodequery]; }-(void) geocodequery{if (addressstring = = Nil | |
[addressstring length] = = 0) {return;
} clgeocoder *geocoder = [[Clgeocoder alloc] init]; [Geocoder geocodeaddressstring:addressstring completionhandler:^ (Nsarray *placemarks, NSError *error)
{NSLog (@ "Query records:%ld", [Placemarks Count]);
if ([placemarks count] > 0) {[_mapview removeannotations:_mapview.annotations]; for (int i = 0; i < [Placemarks count]; i++) {clplacemark* placemark = plaCemarks[i]; Adjust map position and zoom ratio mkcoordinateregion viewregion = mkcoordinateregionmakewithdistance (placemark.location.coordinate, 100
00, 10000);
[_mapview setregion:viewregion Animated:yes];
MapLocation *annotation = [[MapLocation alloc] init];
annotation.streetaddress = Placemark.thoroughfare;
annotation.city = placemark.locality;
Annotation.state = Placemark.administrativearea;
Annotation.zip = Placemark.postalcode;
Annotation.coordinate = placemark.location.coordinate;
[_mapview addannotation:annotation];
}
}]; #pragma mark Map View Delegate Methods-(Mkannotationview *) Mapview: (Mkmapview *) Themapview viewforannotation: (ID < mkannotation>) Annotation {Mkpinannotationview *annotationview = (Mkpinannotationview *) [_mapview DequeueReusableA
nnotationviewwithidentifier:@ "Pin_annotation"];
if (Annotationview = = nil) {Annotationview = [[Mkpinannotationview alloc] Initwithannotation:annotation reuseidentifier:@ "Pin_annotation"];
} Annotationview.pincolor = Mkpinannotationcolorpurple;
Annotationview.animatesdrop = YES;
Annotationview.canshowcallout = YES;
return annotationview; }-(void) Mapview: (Mkmapview *) Mapview didupdateuserlocation: (mkuserlocation *) Userlocation {_
Mapview.centercoordinate = userLocation.location.coordinate; }-(void) Mapviewdidfailloadingmap: (Mkmapview *) Themapview witherror: (nserror *) error {NSLog (@ "error:%@", [Error DESCR
Iption]); } @end
MapLocation.h
#import <MapKit/MapKit.h>
@interface maplocation:nsobject<mkannotation>
//Street Info Properties
@ Property (nonatomic, copy) NSString *streetaddress;
City Information attribute
@property (nonatomic, copy) NSString *city;
State, provincial and municipal information
@property (nonatomic, copy) NSString *state;
Zip code
@property (nonatomic, copy) NSString *zip;
Geographical coordinates
@property (nonatomic, ReadWrite) cllocationcoordinate2d coordinate;
Maplocation.m
Map Call function
#import "MapLocation.h"
@implementation maplocation
-(NSString *) title {return
@ "your location!";
}
-(NSString *) subtitle {
nsmutablestring *ret = [nsmutablestring new];
if (_state)
[ret appendstring:_state];
if (_city)
[ret appendstring:_city];
if (_city && _state)
[ret appendstring:@ ","];
if (_streetaddress && (_city | | _state | | _zip))
[ret appendstring:@ "·"];
if (_streetaddress)
[ret appendstring:_streetaddress];
if (_zip)
[ret appendformat:@ ",%@", _zip];
return ret;
}
@end