IOS learning: using the GoogleMaps SDK in IOS development

Source: Internet
Author: User

 


1. Apply for a free API KEY
To use the GoogleMaps SDK, you must apply for an api key for your application. The API Key allows you to monitor the api calls of your application. The api key is free. You can use it in any application that calls the Map api. You can provide the bundle identifier of your application on the Google APIs Console) to obtain an api key. With the api key, you need to add it to AppDelegate.

 


To obtain the api key, follow these steps:

1. Create an api project on the Google APIs Console

2. On the open api project page, select the Services panel on the left and enable the Google Maps SDK for iOS option.

3. Select the API Access panel and click Create new ios key.

 

4. Enter one or more bundle identifier (one per line)

5. Click Create to Create

6. Find the Key for iOS apps (with bundle identifiers) on the page and copy the api key. Api key created ....

2. Add Google Maps SDK for IOS to the Project
Google
The Maps SDK for iOS is a static framework that contains a resource package. The following describes how to add a framework and configure a project:

1. Create a new project. Do not check StoryBoard. You must use arc.

2. Drag the downloaded GoogleMaps. framework package to the Frameworks folder of the Project. Remember to select Copy
Items into destination group's folder.

3. In your project, right-click the added GoogleMaps. framework and select show
In finder)

4. Drag GoogleMaps. bundle in the Resources folder to the project, preferably in the Frameworks folder. Do not select Copy during import.
Items into destination group's folder

5. Select a project and the target of the application

6. Open Build
On the Phases page, add the following frameworks to the Link Binary with Libraries category:

AVFoundation. framework

CoreData. framework

CoreLocation. framework

CoreText. framework

GLKit. framework

ImageIO. framework

Libc ++. dylib

Libicucore. dylib

Libz. dylib

OpenGLES. framework

QuartzCore. framework

SystemConfiguration. framework

7. Select Build in the project
Settings page

Change the default value in ubuntures to armv7.

In Other
Add-ObjC to Linker Flags. If these options are invisible, you can select all in the top filter.

8. Finally, put the API
Add Key to AppDelegate

Import package: # import
<GoogleMaps/GoogleMaps. h>

In the didfinishlaunchingwitexceptions: Method of the. m file, add:


[Cpp]
<SPAN style = "WHITE-SPACE: pre"> </SPAN> [GMSServices provideAPIKey: @ "YOUR_API_KEY"];

[GMSServices provideAPIKey: @ "YOUR_API_KEY"];
3. Add a map to ViewController


[Cpp]
-(Void) viewDidLoad
{
[Super viewDidLoad];
// Do any additional setup after loading the view.
// Create a GMSCameraPosition that tells the map to display the specified vertex under the specified zoom level
GMSCameraPosition * camera = [GMSCameraPosition cameraWithLatitude:-22.86 longpolling: 151.20 zoom: 6];
MapView _ = [GMSMapView mapWithFrame: CGRectMake (0, 0, self. view. frame. size. width, self. view. frame. size. height) camera: camera];
[Self. view addSubview: mapView _];

// Mark a map
GMSMarker * marker = [[GMSMarker alloc] init];
Marker. position = CLLocationCoordinate2DMake (-22.86, 151.20 );
Marker. title = @ "sysydney ";
Marker. snippet = @ "Australia ";
Marker. map = mapView _;
}

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.