IOS Mkmapview Embedding Maps

Source: Internet
Author: User
Tags uikit

To see that Google Map, the implementation is also quite simple. You need to mkmapview this class when embedding a map, it has many methods and properties, but if you just want to get the basic positioning function, simply instantiate a pair of images and add them to the current view. < a > First introduction, it's a few common properties. The portion of the region used to set up the map is shown, which is a struct, defined as follows: TypeDef struct{CLLOCATIONCOORDINATE2D center;//represents the center of the display Mkcoordinat        Espan span; Represents the scale}mkcoordinateregion; for Mkcoordinatespan it is defined as follows: TypeDef struct{cllocationdegrees LATITUDEDELTA;//This type is described in the previous section, is a double type of cllocationdegrees Longitudedlta;} Mkcoordinatespan; Take a look at the Maptype property, which is used to set the type of the map as follows: Maptype Property Value Description Mkmaptypestandard represents a standard street level Map Mkmaptypesatellite said the satellite figure Mkmaptypehybird said that the above two of the mixture of the rest will not be introduced, to look at the relevant documents, where the map has been able to get out. < two > Let's change the code in the previous section:. h header file #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @interface Corelocationviewcontroller:uiviewcontroller<cllocationmanagerdelegate,        mkmapviewdelegate>{Mkmapview *map;        Cllocationmanager *locmanager; Cllocationcoordinate2d Loc;} @property (nonatomic, retain) Mkmapview *map; @property (nonatomic, retain) Cllocationmanager *locmanager;-(void) Setcurrentlocation: (cllocation *) location; @end. m source file #import "CoreLocationViewController.h" @implementation Corelocationviewcontroller@synthesize map; @synthesize locmanager;-(void) viewdidload {map = [[Mkmapview alloc]init        Withframe:cgrectmake (0.0f, 0.0f, 320.0f, 411.0f)];        Map.showsuserlocation = YES;        [Self.view Addsubview:map];        Locmanager = [[Cllocationmanager alloc] init];        Locmanager.delegate = self;        Locmanager.desiredaccuracy = Kcllocationaccuracybest;        Locmanager.distancefilter = 100;        [Locmanager startupdatinglocation]; [Super Viewdidload];}        -(void) Dealloc {[map release];        [Locmanager release]; [Super Dealloc];} #pragma mark-#pragma mark Core location Delegate methods-(void) Locationmanager: (Cllocationmanager *) Manager didup               Datetolocation: (cllocation *) newlocation    Fromlocation: (cllocation *) oldlocation {NSLog (@ "---------------");        LOC = [NewLocation coordinate];        Mkcoordinateregion region;        Mkcoordinatespan span; span.latitudedelta=0.1; Zoom level span.longitudedelta=0.1;        Zoom level NSLog (@ "%f", loc.latitude);        NSLog (@ "%f", loc.longitude);        Region.span=span;        Region.center=loc;         Map.showsuserlocation=no;        Map.maptype = Mkmaptypestandard;        [Map setregion:region Animated:yes]; [Map regionthatfits:region];} -(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error{nsstring *errorme        Ssage;        if ([error code] = = kclerrordenied) {errormessage = @ "denied access";        } if ([error code] = = Kclerrorlocationunknown) {errormessage = @ "";                 } Uialertview *alert = [[Uialertview alloc] Initwithtitle:nil                                 Message:errormessage delegate:self cancelbuttontitle:@ "Helicopter 畾" other        Buttontitles:nil];        [Alert show]; [Alert release];}        -(void) Setcurrentlocation: (cllocation *) location {mkcoordinateregion;        Region.center = location.coordinate;        Region.span.longitudeDelta = 0.15f;        Region.span.latitudeDelta = 0.15f; [Map Setregion:region Animated:yes];} @end

IOS Mkmapview Embedding Maps

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.