IOS_21 Group Purchase _ map function

Source: Internet
Author: User

Eventually:




Back to the User location button in the lower right corner:




Mapcontroller Controller,

is the corresponding controller for the map button on the left dock of the main controller ,

Inherit from Showdealdetailcontroller,

Therefore, auto has the function of displaying the purchase details controller

  mapcontroller.h//  Handsome _ buy////  Created by Beyond on 14-8-14.//  Copyright (c) 2014 Com.beyond. All rights reserved.//  dock above the "map" button corresponding to the controller, inherited from the ShowDealDetailController.h controller, automatically has the display Purchase details controller function #import " ShowDealDetailController.h "@interface Mapcontroller:showdealdetailcontroller@end


mapcontroller.m//Handsome _ buy////Created by Beyond on 14-8-14.//Copyright (c) 2014 Com.beyond. All rights reserved.//Dock above the "map" button corresponding to the controller, inherited from the ShowDealDetailController.h controller, automatically has the display Purchase details controller function #import " MapController.h "#import <MapKit/MapKit.h> #import" DealRequestTool.h "#import" MetaDataTool.h "#import" LocationTool.h "//member has latitude and longitude coordinates #import" City.h "//a merchant model #import" Business.h "#import" Deal.h "//A PIN model that provides a data source for pin View # Import "MyAnnotation.h"//longitude and latitude across the # define Kspan mkcoordinatespanmake (0.018404, 0.031468) @interface Mapcontroller ()    <mkmapviewdelegate>{Mkmapview *_mapview; Nsmutablearray *_showingdeals;}            @end @implementation mapcontroller-(void) viewdidload{[Super Viewdidload];    Self.title = @ "Map"; 0. Monitoring the notification of the completion of the location ..... There's a problem here. Kaddallnotes (DataChange)//1. Add map Mkmapview *mapview = [[Mkmapview alloc] InitWithFrame:self.view.bou    NDS]; Mapview.autoresizingmask = Uiviewautoresizingflexibleheight |    Uiviewautoresizingflexiblewidth; Show user's location point mApview.showsuserlocation = YES;    Set proxy mapview.delegate = self;        [Self.view Addsubview:mapview];            2. Initialize array _showingdeals = [Nsmutablearray array];    3. Add the button back to the user's location [self addbacktouserlocationbtn]; }-(void) addbacktouserlocationbtn{//3. Add a button back to the user's location UIButton *backuserbtn = [UIButton buttonwithtype:uibuttontypecus    Tom];    Cgsize imgsize = [backuserbtn setbtnbgimgfornormal:@ "Btn_map_locate.png" highlightedname:@ "Btn_map_locate_hl.png"];    CGFloat w = imgsize.width;    CGFloat h = imgsize.height;    CGFloat margin = 20;    CGFloat x = self.view.frame.size.width-w-margin;    CGFloat y = self.view.frame.size.height-h-margin;    The button is in the lower right corner so the left margin and the top margin are automatically scaled backuserbtn.frame = CGRectMake (x, Y, W, h); Backuserbtn.autoresizingmask = Uiviewautoresizingflexibleleftmargin |    Uiviewautoresizingflexibletopmargin; [Backuserbtn addtarget:self Action: @selector (backtouserlocationbtnclicked) forControlEvents:    UIControlEventTouchUpInside]; [Self.vieW ADDSUBVIEW:BACKUSERBTN];} The return to User Center Point button is clicked-(void) backtouserlocationbtnclicked{//Mapview contains the user's location information (the annotation representing the users ' Loc    ation) Cllocationcoordinate2d Center = _mapview.userlocation.location.coordinate;    Mkcoordinateregion region = Mkcoordinateregionmake (center, Kspan); Set center point [_mapview setregion:region animated:yes];} The proxy method of the #pragma mark-mapview #pragma mark is called when the user is located (very high frequency of calls)---2-(void) Mapview: (Mkmapview *) Mapview        Didupdateuserlocation: (mkuserlocation *) userlocation{//Only Let it first locate the user coordinates if (_mapview) return;        1. User location (center point) cllocationcoordinate2d Center = userLocation.location.coordinate;        2. After determining the center point, then determine the span (range)//Mkcoordinatespan span = Mkcoordinatespanmake (0.018404, 0.031468);        3. Based on the center point and span, the area mkcoordinateregion region = Mkcoordinateregionmake (center, Kspan) is determined;    4. Let the Mapview display to the specified area [Mapview setregion:region Animated:yes];                    _mapview = Mapview;    Set the center point coordinates for the user's coordinates ...[Mapview setCenterCoordinate:userLocation.location.coordinate animated:yes];} #pragma mark drag the map (the area of the map is changed) it calls-(void) Mapview: (Mkmapview *) Mapview regionwillchangeanimated: (BOOL) animated{//1.        The center position of the current display area of the map cllocationcoordinate2d pos = mapView.region.center; Calculates the city name according to the center point position coordinates,//2. Use the tool class to send requests to the server [[Dealrequesttool Shareddealrequesttool] Dealsrequestwithpos:pos success        : ^ (nsarray *deals, int total_count) {//Iterate through the returned deals array and compare to the deals array saved by the current controller, if the deal has been shown, continue skips, For (Deal *d in deals) {//already shown, skip, avoid pin shadow burn if ([_showingdeals containsobject:d]) contin                        Ue                        If the returned deal, never shown, is added to the member array first, then the member of the group: quotient area, each with a pin to display to Mapview above [_showingdeals addobject:d]; An array of merchant objects that traverse this group of deals (business *b in d.businesses) {//a merchant corresponds to a pin model, which is the data source, for annotation V Iew provides data//Annotation is a model that is used to mark coordinates//implement proxy Mapview on a map:Viewforannotation: Method, return each annotation corresponding annotation View myannotation *anno = [[Myannotation alloc] init];                Anno.business = b;                Anno.deal = D;                Anno.coordinate = Cllocationcoordinate2dmake (B.latitude, b.longitude);            Important ~ ~ ~ Provide data for Mapview, then come to Method mapview:viewforannotation: [Mapview Addannotation:anno];    }}} error:^ (Nserror *error) {log (@ "Error---%@", error);            }]; The proxy method for the #pragma mark-mapview//is similar to cell for Row, providing a view for each annotation, where a custom annotation model is used-(Mkannotationview *) Mapview :(Mkmapview *) Mapview viewforannotation: (myannotation *) annotation{if (![        Annotation Iskindofclass:[myannotation class]) return nil;    1. Remove the pin view static nsstring *id = @ "Mkannotationview" from the cache pool;        Mkannotationview *annoview = [Mapview dequeuereusableannotationviewwithidentifier:id]; 2. The cache pool does not have a recyclable pin view if (Annoview = = nil) {//should be used MkpinannotationviEW this subclass, a data source model must be provided when constructing annotationview annotation annoview = [[Mkpinannotationview alloc] Initwithannotation:annotati    On Reuseidentifier:id];        }//3. Set the PIN information for the view to provide a unique data source model annoview.annotation = annotation;        4. Set Picture Annoview.image = [UIImage ImageNamed:annotation.icon]; return Annoview;} #pragma mark clicked on the Pin-(void) Mapview: (Mkmapview *) Mapview Didselectannotationview: (Mkannotationview *) view{//0. If the system comes with Pin, then return directly ... if (![    View.annotation Iskindofclass:[myannotation class]) {return;    }//1. Call the parent class method, show the detail controller, and provide the data source myannotation *anno = view.annotation;        [Self showDetail:anno.deal];        2. Center the selected pin (to become the center point) [Mapview setCenterCoordinate:anno.coordinate Animated:yes]; 3. Bring some shadow effects to the view perimeter View.layer.shadowColor = [Uicolor Bluecolor].    Cgcolor;    view.layer.shadowOpacity = 1; View.layer.shadowRadius = 10;} #pragma mark-Monitor re-refreshes webview//when the location city changes 0. Listen for notification of location completion-(void) datachange{//1. City *city = [MeTadatatool sharedmetadatatool].currentcity;    Clgeocoder *geo = [[Clgeocoder alloc] init];                Global Search for XXX cities [Geo GeocodeAddressString:city.name completionhandler:^ (Nsarray *placemarks, Nserror *error) {        Positioning, after parsing, you can provide latitude and longitude clplacemark *place = placemarks[0];        1. User location (center point) cllocationcoordinate2d Center = place.location.coordinate;        City.position = place.location.coordinate;        Important, the city with tools to remember, because when sending the request, also used the city name and latitude and longitude [locationtool sharedlocationtool].locationcity = cities; 2. After determining the center point, then determine the span (range)//3. After the center point and the span, the area mkcoordinateregion region = Mkcoordinateregionmake (center, K        Span);    4. Let the Mapview display to the specified area [_mapview setregion:region Animated:yes]; }];} @end











IOS_21 Group Purchase _ map function

Related Article

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.