{"id":139,"date":"2016-09-15T05:51:29","date_gmt":"2016-09-14T20:51:29","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=139"},"modified":"2017-02-10T13:55:43","modified_gmt":"2017-02-10T04:55:43","slug":"swift-google-map-api-for-ios%e3%82%92%e5%ae%9f%e8%a3%85%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/swift-google-map-api-for-ios%e3%82%92%e5%ae%9f%e8%a3%85%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95\/","title":{"rendered":"[swift] Google MAP API for iOS\u3092\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u307e\u3068\u3081"},"content":{"rendered":"<h2>Google MAP API for iOS\u3092\u5b9f\u88c5<\/h2>\n<h3>pod\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>\u4e0b\u8a18pod\u3092pod\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u8a18\u3057\u3001pod\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<pre>pod 'GoogleMaps'<\/pre>\n<p>*pod\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0b\u8a18\u53c2\u7167<br \/>\n<a href=\"http:\/\/blue-bear.jp\/kb\/objective-c-pod%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%99%E3%82%8B%E6%96%B9\/\">[objective-c] pod\u3092\u4f7f\u7528\u3057\u3066\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5<\/a><\/p>\n<h3>Google Developer Console\u306b\u30ed\u30b0\u30a4\u30f3<\/h3>\n<p><a href=\"https:\/\/console.developers.google.com\/\" target=\"_blank\">https:\/\/console.developers.google.com\/<\/a><\/p>\n<h3>\u65b0\u3057\u3044Google\u30d7\u30ed\u30b8\u30a7\u30af\u30c8<\/h3>\n<p>Google Developer Console\u3067\u65b0\u3057\u3044xcode\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210<\/p>\n<h3>Google MAP API for iOS\u6709\u52b9<\/h3>\n<p>Google MAP API for iOS\u3092\u9078\u629e\u2192\u6709\u52b9<\/p>\n<h3>\u30ad\u30fc\u4f5c\u6210<\/h3>\n<p>\u8a8d\u8a3c\u753b\u9762\u306b\u306a\u308b\u306e\u3067\u3001\u30ad\u30fc\u3092\u4f5c\u6210<br \/>\n\u30ad\u30fc\u540d\u306f\u9069\u5f53\u306b\u3001\u30d0\u30f3\u30c9\u30eb\u540d\u306f\u30a2\u30d7\u30ea\u306e\u30d0\u30f3\u30c9\u30eb\u540d\u3092\u8ffd\u52a0<br \/>\nAPI\u30ad\u30fc\u304c\u6255\u3044\u51fa\u3055\u308c\u308b\u306e\u3067\u3001\u30b3\u30d4\u30fc<\/p>\n<h3>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\uff1aAppDelegate<\/h3>\n<pre>\r\nimport UIKit\r\nimport GoogleMaps;  \/\/\u8ffd\u8a18\r\n\r\n@UIApplicationMain\r\nclass AppDelegate: UIResponder, UIApplicationDelegate {\r\n\r\n    var window: UIWindow?\r\n    let cGoogleMapsAPIKey = \"Google\u3067\u53d6\u5f97\u3057\u305fAPIKey\"  \/\/\u8ffd\u8a18\r\n\r\n    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {\r\n\r\n        GMSServices.provideAPIKey(cGoogleMapsAPIKey) \/\/\u8ffd\u8a18\r\n\r\n        return true\r\n    }\r\n}\r\n<\/pre>\n<h3>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\uff1aViewController<\/h3>\n<pre>import Foundation\r\nimport GoogleMaps\r\n\r\nclass homeViewController: UIViewController {\r\n    \r\n    var googleMap : GMSMapView!\r\n    \r\n    \/\/\u7def\u5ea6\u7d4c\u5ea6 -&gt; \u6709\u697d\u753a\r\n    let latitude: CLLocationDegrees = 35.6824745\r\n    let longitude: CLLocationDegrees = 139.755561\r\n\r\n    \/\/\u7def\u5ea6\u7d4c\u5ea6 -&gt; \u6771\u4eac\u99c5\r\n    let latitude2: CLLocationDegrees = 35.681298\r\n    let longitude2: CLLocationDegrees = 139.766247\r\n    \r\n    \r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \r\n        let width = self.view.frame.maxX\r\n        let height = self.view.frame.maxY\r\n        \r\n        \/\/ \u30ba\u30fc\u30e0\u30ec\u30d9\u30eb.\r\n        let zoom: Float = 15\r\n        \r\n        \/\/ \u30ab\u30e1\u30e9\u3092\u751f\u6210.\r\n        let camera: GMSCameraPosition = GMSCameraPosition.cameraWithLatitude(latitude,longitude: longitude, zoom: zoom)\r\n        \r\n        \/\/ MapView\u3092\u751f\u6210.\r\n        googleMap = GMSMapView(frame: CGRectMake(0, 0, width, height))\r\n        \r\n        \/\/ MapView\u306b\u30ab\u30e1\u30e9\u3092\u8ffd\u52a0.\r\n        googleMap.camera = camera\r\n        \r\n        \/\/\u30de\u30fc\u30ab\u30fc\u306e\u4f5c\u6210\r\n        let marker: GMSMarker = GMSMarker()\r\n        marker.position = CLLocationCoordinate2DMake(latitude, longitude)\r\n        marker.icon = GMSMarker.markerImageWithColor(UIColor.blueColor()) \/\/\u30de\u30fc\u30ab\u30fc\u306e\u8272\u3092\u9752\u306b\r\n        marker.opacity = 0.6 \/\/\u30de\u30fc\u30ab\u30fc\u306e\u900f\u660e\u5ea6\u30920.6\u306b\r\n        marker.map = googleMap\r\n\r\n        \/\/\u3082\u3046\uff11\u500b\u30de\u30fc\u30ab\u30fc\u4f5c\u6210\r\n        let othermarker: GMSMarker = GMSMarker()\r\n        othermarker.position = CLLocationCoordinate2DMake(latitude2, longitude2)\r\n        othermarker.title = \"London\";\r\n        othermarker.snippet = \"Population: 8,174,100\"\r\n        othermarker.icon = UIImage(named: \"house.png\") \/\/\u30de\u30fc\u30ab\u30fc\u3092\u753b\u50cf\u306b\r\n        othermarker.opacity = 0.1 \/\/\u30de\u30fc\u30ab\u30fc\u306e\u900f\u660e\u5ea6\u30920.6\u306b\r\n        othermarker.map = googleMap\r\n\r\n\r\n        \/\/\u3082\u3046\uff11\u500b\u306e\u30de\u30fc\u30ab\u30fc\u5468\u8fba\u306b\u8584\u3044\u9752\u306e\u5186\u3092\u63cf\u753b\r\n        let circleCenter = CLLocationCoordinate2DMake(latitude2, longitude2);\r\n        let circ = GMSCircle(position: circleCenter, radius: 1000) \/\/\u534a\u5f841000\u30e1\u30fc\u30c8\u30eb\u306e\u5186\r\n        circ.fillColor = UIColor(red: 0, green: 0, blue: 0.35, alpha: 0.2)\r\n        circ.strokeColor = UIColor.blueColor()\r\n        circ.map = googleMap;\r\n\r\n\r\n        let path = GMSMutablePath() \/\/\u7dda\u306e\u6e96\u5099\r\n        path.addCoordinate(CLLocationCoordinate2DMake(latitude, longitude)) \/\/\u6709\u697d\u753a\u304b\u3089\r\n        path.addCoordinate(CLLocationCoordinate2DMake(latitude2, longitude2)) \/\/\u6771\u4eac\u99c5\u307e\u3067\r\n        let polyline = GMSPolyline(path: path) \/\/\u7dda\u3092\u4f5c\u6210\r\n        polyline.strokeWidth = 3.0\/\/\u7dda\u306e\u592a\u3055\r\n        polyline.map = googleMap\/\/\u7dda\u3092\u63cf\u753b\r\n        \r\n        \r\n        \/\/view\u306bMapView\u3092\u8ffd\u52a0.\r\n        self.view.addSubview(googleMap)\r\n        \r\n    }\r\n    \r\n    override func didReceiveMemoryWarning() {\r\n        super.didReceiveMemoryWarning()\r\n        \/\/ Dispose of any resources that can be recreated.\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Google MAP API for i<\/p>\n","protected":false},"author":1,"featured_media":920,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[19,20,21],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/139"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":8,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":250,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/139\/revisions\/250"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}