2016-07-29 15 views
0

以下のコードは、私が添付したもののようなリストから1つを選択すると、その場所を返します。画面を引き継ぐことは可能ですか? GoogleプレイスIOS swift

私の質問: すべての場所の詳細を所定の座標に保存する機能はありますか?たとえば、座標が(51.5108396、-0.0922251)の場合、付近の場所のすべての情報を取得するにはどうすればよいですか?私はJsonに慣れていない。私が欲しいものに近い例はありますか?どうもありがとう。

この関数placesClient.currentPlaceWithCallbackは何とか近いですが、ユーザーの現在の座標を使用するためカスタム座標を使用できません。

//https://developers.google.com/places/ios-api/placepicker 
let center = CLLocationCoordinate2DMake(51.5108396, -0.0922251) 
let northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001) 
let southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001) 
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest) 
let config = GMSPlacePickerConfig(viewport: viewport) 
let placePicker = GMSPlacePicker(config: config) 
placePicker?.pickPlaceWithCallback({ (place: GMSPlace?, error: NSError?) -> Void in 
    if let error = error { 
     print("Pick Place error: \(error.localizedDescription)") 
     return 
    } 
    if let place = place { 
     print("Place name \(place.name)") 
     print("Place address \(place.formattedAddress)") 
     print("Place attributions \(place.attributions)") 
    } else { 
     print("No place selected") 
    } 
}) 

enter image description here

+0

を変更しました。 Googleは場所に関する情報を取得するためのさまざまなAPIを提供しています。いくつかはユーザーと対話し、クエリを作成して結果を返すバックエンドAPIもあります(メモリが使用されている場合はJSON)。必要なことを定義し、それを可能にするAPIを見つける必要があります。 –

+0

私の質問をちょうど更新しました。 Jsonの例はありますか? –

+0

おそらく、そうです。しかし、私はあなたのためにあなたの仕事をするつもりはありません。あなたのようにGoogleのドキュメントを検索する必要があります。 –

答えて

0

Fetching nearby places using google maps 何かが原因アップグレードのiOSバージョンに変更されます。

完全には、あなたが求めているものは全く明らかではないが、コード

func fetchPlacesNearCoordinate(coordinate: CLLocationCoordinate2D, radius: Double, types:[String]) { 
    var urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=\("your api key")&location=\(coordinate.latitude),\(coordinate.longitude)&radius=\(radius)&rankby=prominence&sensor=true" 
    let typesString = types.count > 0 ? types.joinWithSeparator("|") : "food" 
    urlString += "&types=\(typesString)" 
    urlString = urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())! 
    UIApplication.sharedApplication().networkActivityIndicatorVisible = true 
    let session = NSURLSession.sharedSession() 
    let placesTask = session.dataTaskWithURL(NSURL(string: urlString)!) {data, response, error in 
     UIApplication.sharedApplication().networkActivityIndicatorVisible = false 
     if let jsonResult = (try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)) as? NSDictionary { 
      let returnedPlaces: NSArray? = jsonResult["results"] as? NSArray 
      if returnedPlaces != nil { 
       for index in 0..<returnedPlaces!.count { 
        if let returnedPlace = returnedPlaces?[index] as? NSDictionary { 
         var placeName = "" 
         var latitude = 0.0 
         var longitude = 0.0 
         if let name = returnedPlace["name"] as? NSString { 
          placeName = name as String 
         } 
         if let geometry = returnedPlace["geometry"] as? NSDictionary { 
          if let location = geometry["location"] as? NSDictionary { 
           if let lat = location["lat"] as? Double { 
            latitude = lat 
           } 
           if let lng = location["lng"] as? Double { 
            longitude = lng 
           } 
          } 
         } 
         print("index", index, placeName, latitude, longitude) 
        } 
       } 
      } 
     } 
    } 
    placesTask.resume() 
} 
関連する問題