[Code Note] offline map and offline Map

Source: Internet
Author: User

[Code Note] offline map and offline Map

I ,.

2. Engineering Drawing.

3. Code.

ViewController. h

#import <UIKit/UIKit.h>#import <CoreLocation/CoreLocation.h>#import "MapLocation.h"@interface ViewController : UIViewController<MKMapViewDelegate>{    MKMapView *_mapView;    NSString *addressString;}@end

 

ViewController. m

# Import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // call the gaode map provided by the system // display the offline map of the current location _ mapView = [[MKMapView alloc] init]; _ mapView. frame = CGRectMake (0, 40,320,400); _ mapView. delegate = self; _ mapView. mapType = MKMapTypeStandard; [self. view addSubview: _ mapView]; addressString = @ ""; NSLog (@ "--- addressString --- % @", addressString); [self geocodeQuery];}-(void) geocodeQuery {if (addressString = nil | [addressString length] = 0) {return;} CLGeocoder * geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString: addressString completionHandler: ^ (NSArray * placemarks, NSError * error) {NSLog (@ "Number of query records: % ld", [placemarks count]); if ([placemarks count]> 0) {[_ mapView removeAnnotations: _ mapView. annotations] ;}for (int I = 0; I <[placemarks count]; I ++) {CLPlacemark * placemark = placemarks [I]; // adjust the map location and zoom ratio MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance (placemark. location. coordinate, 10000,100 00); [_ mapView setRegion: viewRegion animated: YES]; MapLocation * annotation = [[MapLocation alloc] init]; annotation. streetAddress = placemark. thoroughfare; annotation. city = placemark. locality; annotation. state = placemark. administrativeArea; annotation.zip = placemark. postalCode; annotation. coordinate = placemark. location. coordinate; [_ mapView addAnnotation: annotation] ;}}] ;}# pragma mark Map View Delegate Methods-(Progress *) mapView :( MKMapView *) theMapView viewForAnnotation :( id <MKAnnotation>) annotation {comment * annotationView = (MKPinAnnotationView *) [_ mapView comment: @ "PIN_ANNOTATION"]; if (annotationView = nil) {annotationView = [[MKPinAnnotationView alloc] Comment: annotation reuseIdentifier: @ "PIN_ANNOTATION"];} annotationView. pinColor = MKPinAnnotationColorPurple; annotationView. animatesDrop = YES; annotationView. canShowCallout = YES; return annotationView;}-(void) mapView :( MKMapView *) mapView didUpdateUserLocation :( MKUserLocation *) userLocation {_ mapView. centerCoordinate = userLocation. location. coordinate;}-(void) mapViewDidFailLoadingMap :( MKMapView *) theMapView withError :( NSError *) error {NSLog (@ "error: % @", [error description]);} @ end

 

MapLocation. h

# Import <MapKit/MapKit. h> @ interface MapLocation: NSObject <MKAnnotation> // The street information attribute @ property (nonatomic, copy) NSString * streetAddress; // The city information attribute @ property (nonatomic, copy) NSString * city; // state, province, and city information @ property (nonatomic, copy) NSString * state; // zip code @ property (nonatomic, copy) NSString * zip; // geographic coordinate @ property (nonatomic, readwrite) CLLocationCoordinate2D coordinate; @ end

 

MapLocation. m

// Map call function # import "MapLocation. h" @ implementation MapLocation-(NSString *) title {return @ "your location! ";}- (NSString *) subtitle {NSMutableString * ret = [NSMutableString new]; if (_ state) [ret appendString: _ state]; if (_ city) [ret appendString: _ city]; if (_ city & _ state) [ret appendString: @ ","]; if (_ streetAddress & (_ city | _ state | _ zip) [ret appendString: @ "•"]; if (_ streetAddress) [ret appendString: _ streetAddress]; if (_ zip) [ret appendFormat: @ ", % @", _ zip]; return ret ;}@ end

 

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.