質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

0回答

1613閲覧

Error Domain=kCLErrorDomain Code=0 "(null)"

BichaSoken

総合スコア13

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

0クリップ

投稿2020/02/16 10:22

GoogleDirectionのAPiを使い場所を検索するとタイトルのエラーがでます
Error Domain=kCLErrorDomain Code=0 "(null)"

リンク内容
この記事を試してみたのですが解決されませんでした。

他に何の原因が考えられるでしょうか?

import UIKit import GoogleMaps import GooglePlaces import SwiftyJSON import Alamofire enum Location { case startLocation case destinationLocation } class ViewController: UIViewController , GMSMapViewDelegate , CLLocationManagerDelegate { var googleMaps = GMSMapView() @IBOutlet weak var startLocation: UITextField! @IBOutlet weak var destinationLocation: UITextField! var locationManager = CLLocationManager() var locationSelected = Location.startLocation var locationStart = CLLocation() var locationEnd = CLLocation() override func viewDidLoad() { super.viewDidLoad() locationManager = CLLocationManager() locationManager.delegate = self locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.startMonitoringSignificantLocationChanges() //Your map initiation code let camera = GMSCameraPosition.camera(withLatitude: -7.9293122, longitude: 112.5879156, zoom: 15.0) self.googleMaps.camera = camera self.googleMaps.delegate = self self.googleMaps.isMyLocationEnabled = true self.googleMaps.settings.myLocationButton = true self.googleMaps.settings.compassButton = true self.googleMaps.settings.zoomGestures = true } // MARK: function for create a marker pin on map func createMarker(titleMarker: String, iconMarker: UIImage, latitude: CLLocationDegrees, longitude: CLLocationDegrees) { let marker = GMSMarker() marker.position = CLLocationCoordinate2DMake(latitude, longitude) marker.title = titleMarker marker.icon = iconMarker marker.map = googleMaps } //MARK: - Location Manager delegates func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("Error to get location : (error)") } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let location = locations.last // let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 17.0) let locationTujuan = CLLocation(latitude: 37.784023631590777, longitude: -122.40486681461333) createMarker(titleMarker: "Lokasi Tujuan", iconMarker: #imageLiteral(resourceName: "mapspin") , latitude: locationTujuan.coordinate.latitude, longitude: locationTujuan.coordinate.longitude) createMarker(titleMarker: "Lokasi Aku", iconMarker: #imageLiteral(resourceName: "mapspin") , latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!) drawPath(startLocation: location!, endLocation: locationTujuan) // self.googleMaps?.animate(to: camera) self.locationManager.stopUpdatingLocation() } // MARK: - GMSMapViewDelegate func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) { googleMaps.isMyLocationEnabled = true } func mapView(_ mapView: GMSMapView, willMove gesture: Bool) { googleMaps.isMyLocationEnabled = true if (gesture) { mapView.selectedMarker = nil } } func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool { googleMaps.isMyLocationEnabled = true return false } func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) { print("COORDINATE (coordinate)") // when you tapped coordinate } func didTapMyLocationButton(for mapView: GMSMapView) -> Bool { googleMaps.isMyLocationEnabled = true googleMaps.selectedMarker = nil return false } //MARK: - this is function for create direction path, from start location to desination location func drawPath(startLocation: CLLocation, endLocation: CLLocation) { let origin = "(startLocation.coordinate.latitude),(startLocation.coordinate.longitude)" let destination = "(endLocation.coordinate.latitude),(endLocation.coordinate.longitude)" let url = "https://maps.googleapis.com/maps/api/directions/json?origin=(origin)&destination=(destination)&mode=driving" Alamofire.request(url).responseJSON { response in print(response.request as Any) // original URL request print(response.response as Any) // HTTP URL response print(response.data as Any) // server data print(response.result as Any) // result of response serialization let json = try! JSON(data: response.data!) let routes = json["routes"].arrayValue // print route using Polyline for route in routes { let routeOverviewPolyline = route["overview_polyline"].dictionary let points = routeOverviewPolyline?["points"]?.stringValue let path = GMSPath.init(fromEncodedPath: points!) let polyline = GMSPolyline.init(path: path) polyline.strokeWidth = 4 polyline.strokeColor = UIColor.red polyline.map = self.googleMaps } } } // MARK: when start location tap, this will open the search location @IBAction func openStartLocation(_ sender: UIButton) { let autoCompleteController = GMSAutocompleteViewController() autoCompleteController.delegate = self // selected location locationSelected = .startLocation // Change text color UISearchBar.appearance().setTextColor(color: UIColor.black) self.locationManager.stopUpdatingLocation() self.present(autoCompleteController, animated: true, completion: nil) } // MARK: when destination location tap, this will open the search location @IBAction func openDestinationLocation(_ sender: UIButton) { let autoCompleteController = GMSAutocompleteViewController() autoCompleteController.delegate = self // selected location locationSelected = .destinationLocation // Change text color UISearchBar.appearance().setTextColor(color: UIColor.black) self.locationManager.stopUpdatingLocation() self.present(autoCompleteController, animated: true, completion: nil) } // MARK: SHOW DIRECTION WITH BUTTON @IBAction func showDirection(_ sender: UIButton) { // when button direction tapped, must call drawpath func self.drawPath(startLocation: locationStart, endLocation: locationEnd) } } // MARK: - GMS Auto Complete Delegate, for autocomplete search location extension ViewController: GMSAutocompleteViewControllerDelegate { func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) { print("Error (error)") } func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) { // Change map location let camera = GMSCameraPosition.camera(withLatitude: place.coordinate.latitude, longitude: place.coordinate.longitude, zoom: 16.0 ) // set coordinate to text if locationSelected == .startLocation { startLocation.text = "(place.coordinate.latitude), (place.coordinate.longitude)" locationStart = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude) createMarker(titleMarker: "Location Start", iconMarker: #imageLiteral(resourceName: "mapspin"), latitude: place.coordinate.latitude, longitude: place.coordinate.longitude) } else { destinationLocation.text = "(place.coordinate.latitude), (place.coordinate.longitude)" locationEnd = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude) createMarker(titleMarker: "Location End", iconMarker: #imageLiteral(resourceName: "mapspin"), latitude: place.coordinate.latitude, longitude: place.coordinate.longitude) } self.googleMaps.camera = camera self.dismiss(animated: true, completion: nil) } func wasCancelled(_ viewController: GMSAutocompleteViewController) { self.dismiss(animated: true, completion: nil) } func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) { UIApplication.shared.isNetworkActivityIndicatorVisible = true } func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) { UIApplication.shared.isNetworkActivityIndicatorVisible = false } } public extension UISearchBar { public func setTextColor(color: UIColor) { let svs = subviews.flatMap { $0.subviews } guard let tf = (svs.filter { $0 is UITextField }).first as? UITextField else { return } tf.textColor = color } }

関係ないかもしれませんが、エラーはこの箇所に表示されました。

createMarker(titleMarker: "Lokasi Tujuan", iconMarker: #imageLiteral(resourceName: "mapspin") , latitude: locationTujuan.coordinate.latitude, longitude: locationTujuan.coordinate.longitude)

infoの画面です
イメージ説明

初学者ですので具体的に回答していただけると助かります

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

thyda.eiqau

2020/02/18 10:17

エラーメッセージは省略せずにご提示ください。 Xcode上でExeptionにブレークポイントを設定して、クラッシュの原因箇所を特定してください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問