IOS_21 group_map Function
Finally:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + 09lpwr3htcs72lw908o7p8671sowtmwlo%vcd4kpha + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140826/2014082608540575.png" alt = "\">
MapController controller,
Is the Controller corresponding to the Map button on the dock on the left of the master controller,
Inherited from ShowDealDetailController,
Therefore, the system automatically displays the Group Buying details controller.
//// MapController. h // handsome guy _ buy /// Created by beyond on 14-8-14. // Copyright (c) 2014 com. beyond. all rights reserved. // The Controller corresponding to the Map button on the dock, inherited from ShowDealDetailController. h controller, which automatically displays the Group Buying details controller # 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. // The Controller corresponding to the Map button on the dock, inherited from ShowDealDetailController. h controller, which automatically displays the Group Buying details controller # import "MapController. h "# import
# Import "DealRequestTool. h "# import" MetaDataTool ool. h "# import" LocationTool. h "// The Member has latitude and longitude coordinates # import" City. h "// a merchant model # import" Business. h "# import" Deal. h "// a pin model that provides the # import" MyAnnotation of the data source for the pin View. h "// cross-Longitude and latitude # define kSpan MKCoordinateSpanMake (0.018404, 0.031468) @ interface MapController ()
{MKMapView * _ mapView; NSMutableArray * _ showingDeals;} @ end @ implementation MapController-(void) viewDidLoad {[super viewDidLoad]; self. title = @ "map"; // 0. notification of listener positioning completed ..... there is a problem with kAddAllNotes (dataChange) // 1. add map MKMapView * mapView = [[MKMapView alloc] initWithFrame: self. view. bounds]; mapView. autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; // display the user's position in mapView. sho WsUserLocation = YES; // sets the proxy mapView. delegate = self; [self. view addSubview: mapView]; // 2. initialize the array _ showingDeals = [NSMutableArray array]; // 3. click [self addBackToUserLocationBtn];}-(void) addBackToUserLocationBtn {// 3. button UIButton * backUserBtn = [UIButton buttonWithType: UIButtonTypeCustom]; CGSize imgSize = [backUserBtn setBtnBgImgForNormal: @ "Callback" 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 bottom right corner, so the left margin and top margin are automatically scaled backUserBtn. frame = CGRectMake (x, y, w, h); backUserBtn. autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin; [backUserBtn add Target: self action: @ selector (backToUserLocationBtnClicked) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: backUserBtn];} // return to the center of the user and click the-(void) button) backToUserLocationBtnClicked {// mapView stores The user's location information (the annotation representing The user's location) CLLocationCoordinate2D center = _ mapView. userLocation. location. coordinate; MKCoordinateRegion region = MKCoordinateRegionMake (center, KSpan); // set the center [_ mapView setRegion: region animated: YES];} # proxy method of pragma mark-mapView # pragma mark will be called when it locates the user's location (the call frequency is quite high) --- 2-(void) mapView :( MKMapView *) mapView didUpdateUserLocation :( MKUserLocation *) userLocation {// just let it locate the user coordinate for the first time if (_ mapView) return; // 1. CLLocationCoordinate2D center = userLocation. location. coordinate; // 2. after the center point is determined, determine the span (range) // MKCoordinateSpan span = MKCoordinat ESpanMake (0.018404, 0.031468); // 3. based on the center point and span, the region MKCoordinateRegion region = MKCoordinateRegionMake (center, kSpan) is determined. // 4. display mapView to the specified region [mapView setRegion: region animated: YES]; _ mapView = mapView; // set the Center Coordinate to the user's coordinate... // [mapView setCenterCoordinate: userLocation. location. coordinate animated: YES];} # pragma mark: drag the map (the area displayed on the map changes) and call-(void) mapView :( MKMapView *) mapView regionWillChangeAnimated :( BOOL) animated {// 1. the central location of the current map area is CLLocationCoordinate2D pos = mapView. region. center; // calculate the city name based on the coordinates of the center. // 2. use the tool class to send a request to the server [[DealRequestTool sharedDealRequestTool] dealsRequestWithPos: pos success: ^ (NSArray * deals, int total_count) {// traverse the returned deals array, and compare it with the deals array saved by the current controller. If the deal array is already displayed, continue skips and for (Deal * d in deals) {// it has already been displayed. skip this step to avoid the if ([_ showingDeals containsObject: d]) contin from deepening the pin shadow. Ue; // If the returned deal is never displayed, add it to the member array first, and then add the group member: business area, [_ showingDeals addObject: d]; // traverses the merchant object array for (Business * B in d. businesses) {// a merchant corresponds to a pin model, that is, a data source, providing data for the Annotation View. // Annotation is a model used to mark coordinates on the map // implement the mapView of the proxy: viewForAnnotation: method, returns the Annotation View MyAnnotation * anno = [[MyAnnotation alloc] init]; anno. business = B; anno. deal = d; anno. coordinate = CLLocationCoordinate2DMake (B. latitude, B. longpolling); // important ~~~ Provide data for mapView. The following method is displayed: mapView: viewForAnnotation: [mapView addAnnotation: anno] ;}} error: ^ (NSError * error) {log (@ "error --- % @", error) ;}] ;}# proxy method of pragma mark-mapView // similar to cell For Row, providing view For each annotation, the custom Annotation model-(MKAnnotationView *) mapView :( MKMapView *) mapView viewForAnnotation :( MyAnnotation *) annotation {if (! [Annotation isKindOfClass: [MyAnnotation class]) return nil; // 1. retrieve the pin view static NSString * ID = @ "MKAnnotationView" from the cache pool; MKAnnotationView * annoView = [mapView dequeueReusableAnnotationViewWithIdentifier: ID]; // 2. the cache pool does not have a circular pin view if (annoView = nil) {// The MKPinAnnotationView subclass should be used here. When constructing an annotationView, the data source model annotation annoView = [[MKPinAnnotationView alloc] initWithAnnotation: annotation must be provided ReuseIdentifier: ID];} // 3. set the view PIN information to provide a unique data source model annoView. annotation = annotation; // 4. set the image annoView. image = [UIImage imageNamed: annotation. icon]; return annoView;} # pragma mark clicked the pin-(void) mapView :( MKMapView *) mapView didSelectAnnotationView :( MKAnnotationView *) view {// 0. if it is a pin that comes with the system, it will be returned directly... if (! [View. annotation isKindOfClass: [MyAnnotation class]) {return;} // 1. call the method of the parent class to display the details controller and provide the data source MyAnnotation * anno = view. annotation; [self showDetail: anno. deal]; // 2. center the selected pin (becomes the center point) [mapView setCenterCoordinate: anno. coordinate animated: YES]; // 3. make the view area have some shadow effect view. layer. shadowColor = [UIColor blueColor]. CGColor; view. layer. shadowOpacity = 1; view. layer. shadowRadius = 10;} # pragma mark-Refresh webView when the monitored city changes. // 0. listener-(void) dataChange {// 1. city * city = [MetaDataTool ool sharedMetaDataTool ool]. currentCity; CLGeocoder * geo = [[CLGeocoder alloc] init]; // global search for a city [geo geocodeAddressString: city. name completionHandler: ^ (NSArray * placemarks, NSError * error) {// location. After resolution, you can provide the latitude and longitude CLPlacemark * place = placemarks [0]; // 1. CLLocationCoordinate2D center = place. location. coordinate; city. position = place. location. coordinate; // important. Remember the city tool because the city name and latitude [LocationTool sharedLocationTool] are also used when sending the request. locationCity = city; // 2. after determining the center point, determine the span (range) // 3. based on the center point and span, the region MKCoordinateRegion region = MKCoordinateRegionMake (center, kSpan) is determined. // 4. display mapView to the specified region [_ mapView setRegion: region animated: YES];} @ end