iOS Development map and location

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:18px">Using location Services: set the app to have access to location services, first add the following Liang ' ti in the Info.plist file</span></p></p><p><p><span style="font-size:18px"></span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><strong>1.NSLocationWhenInUseUsageDescription <span style="font-family:‘Heiti SC Light‘">during use of the app</span></strong></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><strong>2.NSLocationAlwaysUsageDescription <span style="font-family:‘Heiti SC Light‘">always</span></strong></p></p><span style="font-family:‘Heiti SC Light‘"><span style="font-family:‘Heiti SC Light‘"><br></span></span><span style="font-family:‘Heiti SC Light‘"><span style="font-family:‘Heiti SC Light‘"><br></span></span><span style="font-family:‘Heiti SC Light‘"><span style="font-family:‘Heiti SC Light‘"></span></span><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">#import "ViewController.h"</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">#import <CoreLocation/CoreLocation.h>// <span style="font-family:‘Heiti SC Light‘">Location Services</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">#import <MapKit/MapKit.h>// <span style="font-family:‘Heiti SC Light‘">Map Interface</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">#import "WXAnnotation.h"</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">@interface Viewcontroller () <MKMapViewDelegate></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Cllocationmanager *_manager;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Mkmapview *_mapview;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">@end</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">@implementation Viewcontroller</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">-(void) Viewdidload {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[super viewdidload];</p></p><span style="color:#008493"><span style="color:#008493"><br></span></span><br><p><p><span style="font-size:18px">next, create an object to manage the related location services</span></p></p><p><p><span style="font-size:18px"></span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="color:rgb(0,132,147)"> </span>_manager = [[cllocationmanager alloc] init];</p></p><span style="color:#008493"><span style="color:#008493"><br></span></span><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="color:rgb(0,132,147); font-family:Menlo"> </span> <span style="font-family:Menlo">//manager</span> Judge <span style="font-family:Menlo">:</span> whether the mobile phone to open the location <span style="font-family:Menlo">/app</span> has access to location permissions</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[cllocationmanager locationservicesenabled]; <span style="font-family:‘Heiti SC Light‘">whether the phone is turned</span> on</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[cllocationmanager authorizationstatus]; <span style="font-family:‘Heiti SC Light‘">Status of the app access-targeted permissions</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">If (![ Cllocationmanager locationservicesenabled] | | [cllocationmanager authorizationstatus]! = Kclauthorizationstatusauthorizedwheninuse) {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[_manager requestwheninuseauthorization]; <span style="font-family:‘Heiti SC Light‘">request access to a location service to a user</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><span style="color:#008493"></span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="color:rgb(0,132,147)"> </span>//create a <span style="font-family:‘Heiti SC Light‘">map</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[self createmapview];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="color:rgb(0,132,147)"> </span>//create a <span style="font-family:‘Heiti SC Light‘">pin</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[self createannotationview];</p></p><span style="color:#008493"><span style="color:#008493"><br></span></span><br>}<p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">-(void) Createmapview</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">Create</span> Mapview</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">_mapview = [[mkmapview alloc] initWithFrame:self.view.bounds];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">type of Map</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">_mapview.maptype = mkmaptypestandard;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo"> </span> <span style="font-family:Menlo">//</span> show User's Current Location</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">_mapview.showsuserlocation = YES;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo"> </span> <span style="font-family:Menlo">//</span> whether to locate <span style="font-family:Menlo">(</span> whether to end the User's location <span style="font-family:Menlo">)</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">_mapview.usertrackingmode = mkusertrackingmodefollow;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">_mapview.delegate = self;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[self.view addsubview:_mapview];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><br><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo">//</span> Create a PIN</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">-(void) Createannotationview</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">Create</span> Model <span style="font-family:‘Heiti SC Light‘">Object</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Wxannotation *annotation = [[wxannotation alloc] init];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotation.title = @ " <span style="font-family:‘Heiti SC Light‘">Location of</span> position";</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px"><span style="font-family:Menlo">annotation.subtitle = @ "</span> <span style="font-family:Heiti SC Light"></span> kill, kill, Kill. <span style="font-family:Menlo">!";</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">the structure of the coordinates</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Cllocationcoordinate2d coord = {39.9927359964, 116.3965684639};</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo"> </span> <span style="font-family:Menlo">//</span> The coordinate position where the pin is located</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotation.coordinate = coord;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">add annotations to the</span> Mapview</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[_mapview addannotation:annotation];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo">//</span> Update the User's location (proxy method for map View)</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">-(void) mapview: (mkmapview *) mapview didupdateuserlocation: (mkuserlocation *) userlocation</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">set Mapview according to latitude and longitude</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo"> </span> <span style="font-family:Menlo">//</span> set the area range <span style="font-family:Menlo">to display,</span> set the display precision</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo"> </span> <span style="font-family:Menlo">//</span> Set the display accuracy <span style="font-family:Menlo">(</span> than the column ruler <span style="font-family:Menlo">)</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Mkcoordinatespan span = Mkcoordinatespanmake (0.01, 0.01);</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">the specified range</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Mkcoordinateregion region = Mkcoordinateregionmake (userlocation.location.coordinate,span);</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">Move</span> <span style="font-family:‘Heiti SC Light‘">The location of the Mapview display</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">[_mapview setregion:region animated:yes];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo">//</span> Create a proxy method for the label gaze graph</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">/**</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">* <span style="font-family:‘Heiti SC Light‘">Call Timing</span> : annotation <span style="font-family:‘Heiti SC Light‘">to be added to</span> mapview, <span style="font-family:‘Heiti SC Light‘">coordinates appear in</span> mapview <span style="font-family:‘Heiti SC Light‘"></span> , <span style="font-family:‘Heiti SC Light‘"></span> and <span style="font-family:‘Heiti SC Light‘">a PIN is added to the calling proxy method </span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">*/</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">-(mkannotationview *) mapview: (mkmapview *) mapview viewforannotation: (id<mkannotation>) annotation</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo"> </span> <span style="font-family:Menlo">//</span> current User's location <span style="font-family:Menlo">,</span> no pin displayed</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">If ([annotation iskindofclass:[mkuserlocation class]]) {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Return nil;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Mkannotationview <span style="font-family:‘Heiti SC Light‘">cannot be directly used</span> ( <span style="font-family:‘Heiti SC Light‘">custom pin view</span> , <span style="font-family:‘Heiti SC Light‘">inheritance</span> )</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Mkpinannotationview <span style="font-family:‘Heiti SC Light‘">pin view that can be displayed</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">static NSString *iden = @ "annotation_view";</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">Pin View</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Mkpinannotationview *annotationview = (mkpinannotationview *) [mapview dequeuereusableannotationviewwithidentifier: iden];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">if (annotationview = = Nil) {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotationview = [[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:iden];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">the color of the pin</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotationview.pincolor = mkpinannotationcolorpurple;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">the animation of a pin falling from the sky</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotationview.animatesdrop = YES;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">Show Content</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotationview.canshowcallout = YES;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><span style="font-family:‘Heiti SC Light‘">Secondary View</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotationview.rightcalloutaccessoryview = [UIButton buttonwithtype:uibuttontypedetaildisclosure];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo"> </span> <span style="font-family:Menlo">//</span> Reset pin view <span style="font-family:Menlo">model to</span> solve the problem of reuse</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Annotationview.annotation = annotation;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo; min-height:21px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">Return annotationview;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:18px; font-family:Menlo">}</p></p><br><br><p><p>iOS Development map and location</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.