2017-05-31 26 views
3

私は現在、距離の基準に近い場所の結果が必要なこの機能に固執しています。例えばのために距離でソートされたGoogle APIから近くの場所を取得

: - 私は「高知」を検索すると私はインド に続いて高知だ場合その結果、インドでは日本と同様 である高知、日本2.高知、インドようにする必要がありますこれは一例で

、ユーザーは、などのランドマーク、都市、通りを検索することができます..しかし、私はすべての結果が最初にして遠くの場所が表示されますdistance.Closer結果によってソートすることにしたいです。しかし、要件に応じて結果を得ることができません。

同様の機能は、Android上で行われていると、彼らは(現在の位置から500キロのように)、半径を渡すことによって、それを使用している

私がこれまでにしようとしているもの: - GMSPlacesClient.autocompleteQueryとパッシングを使用して

  • を現在の場所のためにその中に境界GOOGLを使用
GMSPlacesClient().autocompleteQuery(txtLocation.text!, bounds: bounds, filter: filter, callback: {(results, error) -> Void in 
    if let error = error { 
     print("Autocomplete error \(error)") 
     return 
    } 
    if let results = results { 
    } 
}) 
  • ePlaces.placeAutocomplete
GooglePlaces.placeAutocomplete(forInput: self.txtLocation.text!, offset: 0, locationCoordinate: nil, radius: nil, language: nil, types: [GooglePlaces.PlaceType.Regions], components: nil, completion: { (response, error) in 
     // To do       
}) 

答えて

0

私は同じGoogleMaps APIで遊んでいます。私はあなたが要求したのと同じことをしますが、別の方法でコードが添付されています。私はこれを「検索」のボタンで行います。境界線を座標またはマップビューフレームに設定できます。

 let autoCompleteController = GMSAutocompleteViewController() 
 
     autoCompleteController.delegate = self as! GMSAutocompleteViewControllerDelegate 
 
       
 
     // Set bounds to map viewable region 
 
     let visibleRegion = googleMaps.projection.visibleRegion() 
 
     let bounds = GMSCoordinateBounds(coordinate: visibleRegion.farLeft, coordinate: visibleRegion.nearRight) 
 
     
 
     // New Bounds now set to User Location so choose closest destination to user. 
 
     let predictBounds = GMSCoordinateBounds(coordinate: userLocation.coordinate, coordinate: userLocation.coordinate) 
 
     
 
     autoCompleteController.autocompleteBounds = predictBounds 
 
     
 
     // Set autocomplete filter to no filter to include all types of destinations. 
 
     let addressFilter = GMSAutocompleteFilter() 
 
     addressFilter.type = .noFilter 
 
     
 
     autoCompleteController.autocompleteFilter = addressFilter 
 
     
 
     // Change text color 
 
     UISearchBar.appearance().setTextColor(color: UIColor.black) 
 
       
 
     self.present(autoCompleteController, animated: true, completion: nil)

私はとの問題を抱えています:現在の境界のためにユーザーに現在の位置を使用して、それが、私はこれは完全に十分近くでうまくいくと思うことからそのように動作され、その下にGoogle Directionsと計算された距離とマイルを取得してください

関連する問題