https://developers.google.com/maps/documentation/ios/start
首先下载Google Map的sdk for iOS
申请 APIKey
-
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 disable Use Storyboards but ensure that Use Automatic Reference Counting is on.
-
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 theResources
folder to your project. We suggest putting it in 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:
- AVFoundation.framework
- CoreData.framework
- CoreLocation.framework
- CoreText.framework
- GLKit.framework
- ImageIO.framework
- libc++.dylib
- libicucore.dylib
- libz.dylib
- OpenGLES.framework
- QuartzCore.framework
- SystemConfiguration.framework
-
Choose your project, rather than a specific target, and open the Build Settings tab.
-
Replace the default value of Architectures with
armv7
. -
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.
-
Replace the default value of Architectures with
-
Finally, add your API key to your
AppDelegate
.-
#import
<GoogleMaps/GoogleMaps.h>
-
Add the following to your
application:didFinishLaunchingWithOptions:
method, replacing YOUR_API_KEY with your API key.[GMSServices provideAPIKey:@"YOUR_API_KEY"];
添加地图到你的View#import "YourViewController.h" #import <GoogleMaps/GoogleMaps.h> @implementation YourViewController { GMSMapView *mapView_; } // You don't need to modify the default initWithNibName:bundle: method. - (void)loadView { GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683 longitude:151.2086 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086); marker.title = @"Sydney"; marker.snippet = @"Australia"; marker.map = mapView_; }
如果运行之后只显示了添加的图标 ,而没有显示地图 是
APIkey的问题 , ,一般情况下,重新获取下apikey 可以了
-
#import