【发布时间】:2019-04-25 17:05:03
【问题描述】:
如何像 ola 和 uber 一样实时跟踪运输。在我的应用程序中有两种类型的用户驱动程序,用户。我想连续跟踪司机的位置并在谷歌地图上实时显示给用户。我正在使用 swift 4.2 xocode 10.1。任何文档或任何指导都会很重要。
我已经安装了谷歌地图,并指出了出发地点和下车地点,并使用
绘制了一条折线路线https://maps.googleapis.com/maps/api/directions/json?origin这个api。
我还可以从
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) 方法。
我阅读了一些关于实时跟踪的文章文档,就像我必须连续获取驱动程序的 gps 位置并将其发送到 firebase 实时数据库,我再次从用户 firebase 获取位置并且必须移动汽车图像以及用户端的位置。
我做了同样的事情,我将驱动程序位置发送到数据库,也可以获取位置,但无法继续,请帮助。提前致谢
var locationRefrence: StorageReference {
return Storage.storage().reference().child("Locations")
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
print("locations = \(locValue.latitude) \(locValue.longitude)")
if mapViewObj == nil {
mapViewObj = GMSMapView()
let camera = GMSCameraPosition.camera(withLatitude: locValue.latitude, longitude: locValue.longitude, zoom: 16.0)
mapViewObj = GMSMapView.map(withFrame: self.mapView.frame, camera: camera)
mapViewObj.delegate = self
mapViewObj.isMyLocationEnabled = true
mapViewObj.settings.myLocationButton = true
self.mapView.addSubview(mapViewObj)
}
let location = "\(locValue.latitude) \(locValue.longitude)"
firebaseUpload(location: location)
}
func firebaseUpload(location: String) {
let uploadLocationRef = locationRefrence.child("location")
let locationData = location.data(using: .utf8)
let uploadTask = uploadLocationRef.putData(locationData!, metadata: nil) { (metadata, error) in
print(metadata ?? "No metadata")
print(error ?? "No error")
}
uploadTask.observe(.progress) { (snapshot) in
print(snapshot.progress ?? "No progress")
}
uploadTask.resume()
}
func fetchLocationFromFirebase() {
let downloadLocationRef = locationRefrence.child("location")
let downloadTask = downloadLocationRef.getData(maxSize: 1024 * 1024 * 12) { (data, error) in
if let data = data {
let locationStr = String(data: data, encoding: .utf8)
print("Fetched Locations : \(locationStr ?? "Nothing fetched...")")
}
print(error ?? "No error")
}
downloadTask.observe(.progress) { (snapshot) in
print(snapshot.progress ?? "No progress")
}
downloadTask.resume()
}
【问题讨论】:
-
我删除了标题中您要求教程的部分内容。这是题外话,会让你的问题作为题外话结束
-
@Scriptable 谢谢,任何进一步的指导都会对我有很大帮助。
-
你是如何在 firebase 中设置
location的? -
我在 firebase 中制作了一个应用程序并访问了它的存储空间。我可以看到我在 firebase 中提交的数据,也可以获取它。
-
好的,所以驱动程序发送它...用户需要获取它。
标签: ios swift google-maps firebase-realtime-database