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
今回使用するツール・資料
- Xcode
- GoogleMapsPlatform: https://developers.google.com/maps/documentation/ios-sdk/start
- (お店の情報に関するAPI)
実施
- 地図を表示してみよう
[参考] 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