ios - 谷歌地图使用 URL 方案,源位置在 map 中正确显示,目标位置未正确显示

标签 ios swift4 google-maps-sdk-ios url-scheme

enter image description here

let destLat:Float = ((dictionry["Latitude"] as NSString?)?.floatValue)!
let destLong:Float =  ((dictionry["Longitude"] as NSString?)?.floatValue)!
let srcLat:Float =  ((latitude as NSString?)?.floatValue)! //Float(sourcLatitude!)
let strLong:Float = ((longitude as NSString?)?.floatValue)!//Float(sourceLongitude!)
let urlString = "comgooglemaps://?saddr=" + "\(srcLat),\(strLong)" + "&daddr=" + "\(destLat),\(destLong)" + "&directionsmode=driving"

if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
    /*UIApplication.shared.openURL(NSURL(string: "comgooglemaps://?saddr=\(Float(12.972442)),\(Float( 77.580643))&daddr=\(Float(27.0238)),\(Float(74.2179))&directionsmode=driving")! as URL)*/
    UIApplication.shared.openURL(NSURL(string: urlString)! as URL)
} else {
    print("Can't use comgooglemaps://");
    HelperManager.errorAlertUpdate(self, title: ShowAlertTitle, message: "Your device does not contain Maps.")
}

最佳答案

你可以这样写:

objective-c :

 NSString *directionsURL = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",39.190269,-84.359380,39.1899,-84.3598];

if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: directionsURL] options:@{} completionHandler:^(BOOL success) {}];
    } else {
        // Fallback on earlier versions
    }
} else {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: directionsURL]];
}

图片如下所示:

enter image description here

迅速:

   var directionsURL = "http://maps.google.com/maps?saddr=\(39.190269),\(-84.359380)&daddr=\(39.1899),\(-84.3598)"

    if UIApplication.shared.responds(to: Selector("openURL:options:completionHandler:")) {
        if #available(iOS 10.0, *) {
            if let anURL = URL(string: directionsURL) {
                UIApplication.shared.open(anURL, options: [:], completionHandler: {(_ success: Bool) -> Void in
                })
            }
        } else {
            // Fallback on earlier versions
        }
    } else {
        if let anURL = URL(string: directionsURL) {
            UIApplication.shared.openURL(anURL)
        }
    }

关于ios - 谷歌地图使用 URL 方案,源位置在 map 中正确显示,目标位置未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49811380/

相关文章:

在谷歌地图上加载标记的自定义信息窗口时,iOS 应用程序卡住

ios - 未调用 GMSMapViewDelegate 方法?

IOS 谷歌地图相机不指向标记

objective-c - Objective-C - 从当前时间创建角度

ios - 从 url 到 ImageView 显示 Facebook 用户个人资料图像

iphone - 如何使用 ios sdk 从地址簿创建 vCard?

html - 使用 Swift 4 使用 WKWebview 滚动

ios - "Sign in with email"FirebaseUI 形式没有出现在我的屏幕上

ios - 操作无法完成 IDETemplateParseError error1

swift4 - 无法构建 AudioKit AnalogSynthX 示例