Location and map (3) Add a cover layer to the map

Source: Internet
Author: User
Tags border color
-(Void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view. self. mapview = [[mkmapview alloc] initwithframe: Self. view. bounds]; self. mapview. maptype = mkmaptypestandard; self. mapview. scrollenabled = yes; // The map cannot be rotated. mapview. rotateenabled = no; self. mapview. zoomenabled = yes; self. mapview. showsuserlocation = yes; // set the latitude and longitude of the map center cllocationcoordinate2d center = {39.910650, 116.47030}; // set the map display range. The smaller the value, the clearer the mkcoordinatespan span = {0.01, 0.01}; // set mkcoordinateregion region = {center, span}; [self. mapview setregion: Region animated: Yes]; [self. view addsubview: Self. mapview]; uilongpressgesturerecognizer * longgesture = [[uilongpressgesturerecognizer alloc] initwithtarget: Self action: @ selector (longpress :)]; [self. mapview addgesturerecognizer: longgesture]; // sets the proxy self. mapview. delegate = self;}-(void) longpress :( uilongpressgesturerecognizer *) longgesture {// obtain the coordinate cgpoint postion = [longgesture locationinview: Self. mapview]; // converts a long coordinate to a coordinate point at the longitude and latitude, cllocationcoordinate2d coord2d = [self. mapview convertpoint: postion tocoordinatefromview: Self. mapview]; // create a circular covering layer object mkcircle * Circle = [mkcircle circlewithcentercoordinate: coord2d radius: 100]; // Add a single covering layer to the specified level [self. mapview addoverlay: Circle level: margin];} // mkoverlayrenderer returned by this method is used to draw the overwriting control-(mkoverlayrenderer *) mapview :( mkmapview *) mapview rendererforoverlay :( id <mkoverlay>) overlay {mkcircle * Circle = (mkcircle *) overlay; // After ios7, mkxxxrenderer is recommended to render the covering layer control mkcirclerenderer * circlerend = [[mkcirclerenderer alloc] cycle: Circle]; circlerend. alpha = 0.3; // fill color circlerend. fillcolor = [uicolor bluecolor]; // border color circlerend. strokecolor = [uicolor redcolor]; return circlerend ;} ************************* * ******************-(void) longpress :( uilongpressgesturerecognizer *) longgesture {// specify the local image to overwrite nsurl * url = [[nsbundle mainbundle] urlforresource: @ "HMT" withextension: @ "PNG"]; mktileoverlay * tileoverlay = [[mktileoverlay alloc] initwithurltemplate: [url description]; [self. mapview addoverlay: tileoverlay];} // mkoverlayrenderer returned by this method is used to draw the overwriting control-(mkoverlayrenderer *) mapview :( mkmapview *) mapview rendererforoverlay :( id <mkoverlay>) overlay {mktileoverlayrenderer * tilerender = [[mktileoverlayrenderer alloc] initwithoverlay :( mktileoverlay *) Overlay]; tilerender. alpha = 0.2; return circlerend ;}*/

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.