Reputation: 21
I have followed the following steps to integrate Google map sdks to my project
Using an API key enables you to monitor your application's 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 Google Maps SDK for iOS, and it supports an unlimited number of users. You obtain an API key from the Google Developers Console by providing your application's bundle identifier.
If your project doesn't already have a key for iOS applications, follow these steps to create an API key from the Google Developers Console:
In the sidebar on the left, select Credentials. If your project doesn't already have an iOS API key, create one now by selecting Add credentials > API key > iOS key. In the resulting dialog, enter your app's bundle identifier. For example: com.example.hellomap. Click Create.
Your new iOS API key appears in the list of API keys for your project. An API key is a string of characters, something like this:
AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0
To declare the URL schemes used by the Google Maps SDK for iOS, add the following lines to your Info.plist:
<key>LSApplicationQueriesSchemes</key> <array>
<string>googlechromes</string>
<string>comgooglemaps</string> </array>
Adding the Google Maps SDK into your iOS 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.
Launch Xcode and open the project.
Open the Info.plist
file of your project and add two keys to the file:NSLocationWhenInUseUsageDescription
with description you want to display for the permission alert for tracking user location.
NSLocationAlwaysUsageDescription
with description you want to display for the permission alert for tracking user location.
Drag the GoogleMaps.Framework
bundle to the Frameworks group of your project. When prompted, select Copy items into destination group’s folder.
Right-click GoogleMaps.Framework
in your project, and select Show In Finder.
Drag the GoogleMaps.bundle
from the Resources folder to your project. We suggest putting it into the Frameworks group. When prompted, ensure Copy items into destination group’s folder is not selected.
Select your project from the Project Navigator, and choose your application’s target.
Open the Build Phases tab, and within Link Binary with Libraries, add the following frameworks:
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.
Finally, add your API key to your AppDelegate
in the following ways :
In AppDelegate.h add
#import <GoogleMaps/GoogleMaps.h>
In application:didFinishLaunchingWithOptions
method add the following statement replacing the API_KEY
with the API Key you obtained by creating iOS Key.
[GMSServices provideAPIKey:@"API_KEY”];
In code ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <GoogleMapsM4B/GoogleMaps.h>
@interface ViewController : UIViewController
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
ViewController.m
#import "ViewController.h"
#import <GoogleMapsM4B/GoogleMaps.h>
@interface ViewController ()
@end
@implementation ViewController
{
GMSMapView *mapView_;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title=@"LOCATION MAP";
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
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_;
}
-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.hidden = NO;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Problem here is I am not getting any error or warning, only I am able to see the marker but not map, please help me to solve this. I am using xCode7 and IOS9
Upvotes: 1
Views: 741
Reputation: 118
I had this problem just recently and it is an easy fix!
Go to https://console.developers.google.com and click to enable APIs:
Then click on the API needed (in this case probably the Maps for iOS):
And finally, make sure the API is enabled and if it isn't just click to enable!:
Upvotes: 1