LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

openAPIの解説あり!“Googleマップにお店情報を表示するハンズオン”

Last updated at Posted at 2020-05-15

openAPIとは

openAPIとはREST API(*1)のインターフィースに関する定義仕様です。(= openAPIは「仕様」!)
この仕様を元にjsonまたはyamlファイルで記述をします。
またswaggerというツールに記述をすることで、簡単にAPI仕様書を作成することができます。

なぜopenAPI = Swaggerなのか?

もともとAPIの記述方式はopenAPIができるまでは標準化されていませんでした。
SMARTBEARという会社が、SwaggerというAPIの設計と文章化させるツールを開発し、swaggerで設計するにあたってシンプルで扱いやすいAPI開発を促進するためにopenAPIという記述方式を生み出しました。
現在はAPIの記述方式はopenAPIとして標準化されています。

参考: https: //www.openapis.org/about
参考: https://swagger.io/



(※1)REST APIとは
- Webシステムを外部から利用するための、プログラム呼び出し規約の種類で、REST(*2)と呼ばれる設計原則にしたがって定められたものです。
(※2)REST
- プログラムを呼び出すための設計原則
→ 詳しくはこちら: http://e-words.jp/w/REST.html

完成形

<画像>

実施環境(version)

  • Xcode 11.13.5
  • Swift5

今回使用するツール・資料

実施

  1. 地図を表示してみよう

[参考] Google公式サイト
GoogleMapsPlatform: https://developers.google.com/maps/documentation/ios-sdk/start
※GoogleMapSDKを使用するには、XCodeVersion11.0以上である必要がある。

  • iTermを開いてsudo gem install cocoapodsをする。

ロジックを対象の画面に追加する

getCurrentPlace

placesClient.currentPlace(callback: { (placeLikelihoodList, error) -> Void in
if let error = error {
print("Current Place error: \(error.localizedDescription)")
return
}
self.nameLabel.text = "No current place"
self.addressLabel.text = ""
if let placeLikelihoodList = placeLikelihoodList {
let place = placeLikelihoodList.likelihoods.first?.place
if let place = place {
place.coordinate.latitude
self.nameLabel.text = place.name
self.placeName = place.name!
self.addressLabel.text = place.formattedAddress?.components(separatedBy: ", ")
.joined(separator: "\n")
self.latitude = place.coordinate.latitude
self.longitude = place.coordinate.longitude
}
}
})

showMap
```

// Map画面に遷移する
let camera = GMSCameraPosition.camera(withLatitude: self.latitude, longitude: self.longitude, zoom: 15.0)
let mapView = GMSMapView.map(withFrame: self.view.frame, camera: camera)
self.view.addSubview(mapView)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: self.latitude, longitude: self.longitude)
marker.title = self.placeName
marker.snippet = self.placeName
marker.map = mapView
```

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up