Iphone calls google map

Source: Internet
Author: User

 

Use the CLLocationManager class, MKMapView. And implement <MKMapViewDelegate, CLLocationManagerDelegate>

// Initialize CLLocationManager and CLLocationManager to obtain the current geographic coordinate

Locmanager = [[CLLocationManager alloc] init];

 

[Locmanager setDelegate: self];

// Set the accuracy

[Locmanager setDesiredAccuracy: kCLLocationAccuracyBest];

 

[Locmanager startUpdatingLocation];

After execution, the proxy method is automatically called:

 

In the proxy method:

 

 

-(Void) locationManager :( CLLocationManager *) manager didUpdateToLocation :( CLLocation *) newLocation fromLocation :( CLLocation *) oldLocation {

// Initialize the rectangle size

CGRect rect = CGRectMake (0, 0, 320,460 );

// Set the map size to the rectangle size

Map = [[MKMapView alloc] initWithFrame: rect];

 

CLLocationCoordinate2D loc = [newLocation coordinate];

Lat = loc. latitude;

Lon = loc. longpolling;

 

// Coordinate

CLLocationCoordinate2D theCoordinate;

CLLocationCoordinate2D theCenter;

 

// TheCoordinate. latitude = lat;

// TheCoordinate. longpolling = lon;

TheCoordinate = loc;

[Map setDelegate: self];

// Set the map display type, including satellite maps, roads, etc.

[Map setMapType: MKMapTypeStandard];

// [Map setMapType: MKMapTypeSatellite];

// Region coordinate Region (Region, Region)

 

MKCoordinateRegion theRegin;

// TheCenter. latitude = lat;

// TheCenter. longpolling = lon;

TheCenter = loc;

TheRegin. center = theCenter;

 

// Coordinate spacing (span: interval, spacing)

MKCoordinateSpan theSpan;

 

TheSpan. latitudeDelta = 0.1;

TheSpan. longitudeDelta = 0.1;

// Set the area displayed on the map,

TheRegin. span = theSpan;

// [Map setRegion: theRegin];

[Map regionThatFits: theRegin];

Map. showsUserLocation = YES;

[Self. view addSubview: map];

 

}

 

 

-(MKAnnotationView *) mapView :( MKMapView *) mapView viewForAnnotation :( id <MKAnnotation>) annotation {

NSLog (@ "------- viewForAnnotation -------");

// This class can display icons with the same needle

MKPinAnnotationView * newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation: annotationreuseIdentifier: @ "annotation1"];

 

// NewAnnotation. animatesDrop = YES;

// NewAnnotation. animatesDrop = NO;

 

NewAnnotation. pinColor = MKPinAnnotationColorPurple;

// Display flag prompt

NewAnnotation. canShowCallout = YES;

Return newAnnotation;

 

 

 

}

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.