【发布时间】:2017-10-24 07:17:06
【问题描述】:
我如何使用 address 来创建带有 google maps 的路线?不使用 latitude 和 longitude,因为在我的 firebase 中我不使用纬度和经度。我只使用完整地址。
示例:约翰·肯尼迪国际机场,范威克高速公路,牙买加,纽约。
我用 google maps 构建路线的代码:
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if (control as? UIButton)?.buttonType == UIButtonType.detailDisclosure {
mapView.deselectAnnotation(view.annotation, animated: false)
} else if (control as? UIButton)?.buttonType == UIButtonType.custom {
mapView.deselectAnnotation(view.annotation, animated: false)
let alertController = UIAlertController(title: "Выберите навигатор для построение маршрута", message: nil, preferredStyle: .actionSheet)
let googleMaps = UIAlertAction(title: "Google Maps", style: .default, handler: { (action: UIAlertAction) in
if (UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!)) {
let googleUrl = URL(string: "comgooglemaps://?daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=driving")!
UIApplication.shared.open(googleUrl, options: [:], completionHandler: nil)
} else {
let itunesGoogleMaps = URL(string: "https://itunes.apple.com/us/app/google-maps-gps-navigation/id585027354?mt=8")
UIApplication.shared.open(itunesGoogleMaps!, options: [:], completionHandler: nil)
}
})
let cancel = UIAlertAction(title: "Отмена", style: .cancel, handler: nil)
alertController.addAction(googleMaps)
alertController.addAction(cancel)
self.present(alertController, animated: true, completion: nil)
}
}
我使用 variable 从 firebase 获取地址并构建路由:
var studioInfoFromDetail: Hall?
studioInfoFromDetail?.studioAddress
这个变量有rus language的地址。
例子:
Москва,ул。 Правды д.24, строение 3 在英语中应该是 Moscow, Pravdy street, home 24, building 1
Москва, ул.Электрозаводская, д.21 在英语中会如此Moscow, Elektrozavodska street, home 21
那么我该如何放入这个变量中
let googleUrl = URL(string: "comgooglemaps://?daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=driving")!
我的 地址 来自 firebase?
我试着这样写:
let googleUrl = URL(string: "comgooglemaps://?daddr=\(self.studioInfoFromDetail?.studioAddress)&directionsmode=driving")!
但我得到一个零:(
【问题讨论】:
标签: ios swift google-maps street-address