swiftでgoogle places apiにアクセスしようとしています.
googleのPlaces APIのレファレンスにある「周辺検索リクエスト」の項目を参考にしてコードを書きました.
Google Places API Reference
しかし,以下の取得したjsonのようにINVALID_REQUEST
になっていまいます.
このエラーは以下のような条件で発生するようです.
INVALID_REQUEST: 通常は、必須のクエリ パラメータ(location や radius)が指定されていないことを示します。
なぜINVALID_REQUESTになってしまうか分かりません.お願いします.
*REST APIで取得しているので,googleのAPI Managerの認証情報はブラウザキーにしています.リファラーは指定していません.APIはGoogle Maps SDK for iOSとGoogle Places API for iOSとGoogle Places API Web Service を有効にしています.
swift
1import MapKit 2import Alamofire 3class PlaceApiModel: NSObject { 4 5 var location:CLLocationCoordinate2D? 6 var requestURL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json" 7 let accessKey = "*************" 8 9 func getPlaceData() 10 { 11 let locationStr:String = String(location?.longitude)+","+String(location?.latitude) 12 print(locationStr) 13 Alamofire.request(.GET, requestURL, parameters: ["key" : accessKey,"location": locationStr,"radius":500, "types": "food", "name":"cruise"]) 14 .responseJSON {json in 15 if json.result.isSuccess { 16 print(json.request) 17 18 let json2: JSON = JSON(json.result.value!) 19 20 print(json2) 21 } 22 } 23 } 24}
json
1{ 2 "status" : "INVALID_REQUEST", 3 "results" : [ 4 5 ], 6 "html_attributions" : [ 7 8 ] 9}
print(json.request)にて,出力される値は以下になります.
swift
1Optional(<NSMutableURLRequest: 0x13ab7e490> { URL: https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=***&location=139.7228396473%2C35.6469954082&name=cruise&radius=500&types=food })
回答2件
あなたの回答
tips
プレビュー