Call Google Maps in iPhone programs

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
[Locmanagersetdesiredaccuracy: kcllocationaccuracybest];

[Locmanagerstartupdatinglocation];
After execution, the proxy method is automatically called:

In the proxy method:

-(Void) locationmanager :( cllocationmanager *) managerdidupdatetolocation :( 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];

Cllocationcoordinate2dloc = [newlocation coordinate];
Lat = LOC. Latitude;
Lon = LOC. longpolling;

// Coordinate Coordinate
Cllocationcoordinate2dthecoordinate;
Cllocationcoordinate2dthecenter;

// Thecoordinate. Latitude = Lat;
// Thecoordinate. longpolling = Lon;
Thecoordinate = LOC;
[MAP setdelegate: Self];
// Set the map display type, including satellite maps, roads, etc.
[MAP setmaptype: mkmaptypestandard];
// [Mapsetmaptype: mkmaptypesatellite];
// Region coordinate region (region, Region)

Mkcoordinateregiontheregin;
// Thecenter. Latitude = Lat;
// Thecenter. longpolling = Lon;
Thecenter = LOC;
Theregin. Center = thecenter;

// Coordinate spacing (span: interval, spacing)
Mkcoordinatespanthespan;

Thespan. latitudedelta = 0.1;
Thespan. longitudedelta = 0.1;
// Set the area displayed on the map,
Theregin. span = thespan;
// [Mapsetregion: theregin];
[Mapregionthatfits: theregin];
Map. showsuserlocation = yes;
[Self. viewaddsubview: map];

}

-(Mkannotationview *) mapview :( mkmapview *) mapviewforannotation :( id <mkannotation>) annotation {
Nslog (@ "------- viewforannotation -------");
// This class can display icons with the same needle
Mkpinannotationview * newannotation = [[mkpinannotationviewalloc] 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.