Sunday, July 5, 2015

How to add GoogleMaps to an iOS Application?

Steps to follow

Step 1: Create a new iOS project in XCode (Single View Application)

Step 2: Locate GoogleMaps.Framework and GoogleMaps.bundle from your local system ( if you do not find these files, please download them from Google)

Step 3:  Drag these two files into your project. Check the box which says "Copy Items..." and click "Finish"

Step 4: Go to "Build Phases" under targets and expand "Link Binary With Libraries"

Step 5: Click the "+" button to 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
Step 6: Add a new file to your project folder of the type "Objective-C File" and click "Next" button
Step 7: Give any name to the file ( Ex- Test) and click "Create")
Step 8: Now, XCode will bring up a message "  Would you like to configure an Objective-C bridging header?" 
Step 9: Click "Yes" to create a "Bridging Header" file which will act like a bridge between your SWIFT and Objective-C
Step 10: Delete the file "Test.m" which is automatically created 
Step 11: Open the xxxx-Bridging-Header.h and type #import<GoogleMaps/GoogleMaps.h>
Step 12: Please go to "Build Settings"  tab and search for other linker flags
Step 13: Enter -ObjC in the value (Note the - sign and capital letters)
Step 14: Go to link given below "https://console.developers.google.com" and click "Create Project"
Step 15: Here you will find a button named "Create a new key", just click that button 
Step 16: Here it show four types of Key formats, select the "iOS Key" 
Step 17: Here it will display a blank text box, put the "Bundle Identifier" (Ex- com.example.trymaps)
Step 18: Click "Create" and it will create an API Key
Step 19: Go to AppDelegate.swift file and under the method "didFinishLaunchingWithOptions" add the line "GMSServices.provideAPIKey("AIzaSyAeMHNmiIzWrtul1TCsssHaf4arGwVrXyw"
Step 20: Replace the generated API Key from step 18 in the above line
Step 21: Go to main story board and select the "identity inspector", there it displays many text boxes.
Step 22: Click the scrolling bar in front of the label " Class" and select the "GMSMapView"
Step 23: Now run the project and see the GoogleMap on your project. If you get it, then Congratulations :)    
                                Article by - Praveen Kumar and Abhay Shukle
      


   

3 comments: