Haz clic aquí para ver las páginas que has visitado recientemente y las que visitas con más frecuencia.
Google Maps SDK for iOS

Getting Started

Before you can begin working with Google Maps on iOS, you will need to download the Google Maps SDK for iOS and ensure that you have an API key.

Get the Google Maps SDK for iOS

The Google Maps SDK for iOS is distributed as a zip file containing a static framework. After downloading the SDK, you will need to obtain an API key before you can add a map to your application.

Complete release notes are available for each release.

The Google Maps API key

Using an API key enables you to monitor your application's Maps API usage, and ensures that Google can contact you about your application if necessary. The key is free, you can use it with any of your applications that call the Maps API, and it supports an unlimited number of users. You obtain a Maps API key from the Google Developers Console by providing your application's bundle identifier. Once you have the key, you add it to your AppDelegate as described in the next section.

The Google Maps URL scheme is available without an API key.

Create an API project in the Google Developers Console

Follow these steps to create or modify a project for your application in the Google Developers Console and enable the Google Maps SDK for iOS.

  1. Go to the Google Developers Console.
  2. Select a project, or create a new one.
  3. In the sidebar on the left, expand APIs & auth. Next, click APIs. Select the Enabled APIs link in the API section to see a list of all your enabled APIs. Make sure that the API is on the list of enabled APIs. If you have not enabled it, select the API from the list of APIs, then select the Enable API button for the API. The only API you need is the Google Maps SDK for iOS, although you can choose to enable other APIs for the same project too.
  4. In the sidebar on the left, select Credentials.

Get an iOS API key

After following the above steps to activate the API, you end up on the Credentials page in the Google Developers Console, where you can access your project's API keys and other credentials.

  1. If your project doesn't already have a Key for iOS applications, create an API key by selecting Create New Key and then selecting iOS key.
  2. In the resulting dialog, enter one or more bundle identifiers as listed in your application's .plist file. For example: com.example.myapp.
  3. The Google Developers Console displays a section titled Key for iOS applications followed by a forty-character API key, for example:

Add the Google Maps SDK for iOS to your project

The Google Maps SDK for iOS is packaged as a static framework with an included resource bundle. Before you can add a map to your application, you will need to add the framework to your project, and configure your build settings in Xcode. These instructions assume an installation for a new project. If you are working with an existing project, you may not have to follow the steps exactly as described.

  1. Launch Xcode and either open an existing project, or create a new project.
    • If you're new to iOS, create a Single View Application, and ensure that Use Automatic Reference Counting is on.
  2. Drag the GoogleMaps.framework bundle to your project. When prompted, select Copy items if needed.
  3. Right-click GoogleMaps.framework in your project, and select Show In Finder.
  4. Drag the GoogleMaps.bundle from the Resources folder to your project. When prompted, ensure Copy items into destination group's folder is not selected.
  5. Select your project from the Project Navigator, and choose your application's target.
  6. Open the Build Phases tab, and within Link Binary with Libraries, add the following frameworks:
    • 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. Choose your project, rather than a specific target, and open the Build Settings tab.
    • In the Other Linker Flags section, add -ObjC. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.
  8. Finally, add your API key to your AppDelegate.
    • #import <GoogleMaps/GoogleMaps.h>
    • Add the following to your application:didFinishLaunchingWithOptions: method, replacing API_KEY with your API key.
      [GMSServices provideAPIKey:@"API_KEY"];

Upgrade from an earlier version

To upgrade an existing project to the most recent version of the SDK, do the following:

  1. In the Project Navigator, replace the previous framework with the most recent framework.
  2. (Optional) Make any necessary changes as a result of the upgrade. Necessary changes will be described in the release notes.
  3. Clean and rebuild your project by selecting: Product > Clean and then Product > Build.

Add a map

After adding the SDK to your project, and adding your key, you can try adding a map to your application. The code below demonstrates how to add a simple map to an existing ViewController. If you're creating a new app to iOS, first follow the installation instructions above, and create a new Single View Application. Be sure to enable Use Automatic Reference Counting (ARC) if your application is written in Objective-C.

Now, add or update a few methods inside your app's default ViewController to create and initialize an instance of GMSMapView.


#import "YourViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@implementation YourViewController {
  GMSMapView *mapView_;

- (void)viewDidLoad {
  // Create a GMSCameraPosition that tells the map to display the
  // coordinate -33.86,151.20 at zoom level 6.
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
  mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  mapView_.myLocationEnabled = YES;
  self.view = mapView_;

  // Creates a marker in the center of the map.
  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
  marker.title = @"Sydney";
  marker.snippet = @"Australia";
  marker.map = mapView_;



import UIKit

class YourViewController: UIViewController {

  override func viewDidLoad() {

    var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
        longitude: 151.20, zoom: 6)
    var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
    mapView.myLocationEnabled = true
    self.view = mapView

    var marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
    marker.title = "Sydney"
    marker.snippet = "Australia"
    marker.map = mapView

Note: Replace both instances of YourViewController in the above example with the name of your View Controller.

Run your application. You should see a map with a single marker centered over Sydney, Australia. If you see the marker, but the map is not visible, confirm that you have provided your API key.

Experiment with the Google Maps SDK demo project

A demo app is bundled with the Google Maps SDK for iOS. You can import it into Xcode, view the demo, and copy the code to use as a basis for your app.

  1. Follow the instructions to get an API key. When prompted, add the following as an allowed bundle identifier for your key: com.example.SDKDemos
  2. Find the Xcode project in the Google Maps SDK for iOS library that you downloaded:
  3. Open the project in Xcode.
  4. Open the file SDKDemoAPIKey.h and paste the value of your API key into the kAPIKey constant:
    static NSString *const kAPIKey = @"PUT-YOUR-KEY-HERE";
  5. Build and run the project. You should see a list of options for various types of maps. If you don’t see a map when viewing any of the options, there’s probably something wrong with your API key. Check the debugger output for messages.