【问题标题】:Google Maps Using URL Scheme , Source location showing Properly in Maps ,Destination location not showing Properly使用 URL 方案的 Google 地图,源位置在地图中正确显示,目标位置未正确显示
【发布时间】:2018-04-13 07:16:26
【问题描述】:

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.")
}

【问题讨论】:

  • 能提供srcLat和srcLong吗?
  • @DarshitVadodaria 请在下面查看。 var directionURL = "maps.google.com/…)"

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


【解决方案1】:

你可以这样写:

目标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]];
}

图片如下:

迅速:

   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)
        }
    }

【讨论】:

  • 感谢 Mansi Dobariya,在浏览器中正确打开,尝试打开时应用源位置正确显示,目的地显示纬度和经度值。
【解决方案2】:

它显示了正确的目的地,可能没有显示目的地的地址,这就是谷歌地图目前的工作方式。地图没有显示目的地地址。您可以通过交换 saddrdaddr 的值来进行测试,例如

let urlString = "comgooglemaps://?saddr=" + "\(destLat),\(destLong)" 
                               + "&daddr=" + "\(srcLat),\(srcLong)" 
                               + "&directionsmode=driving"

【讨论】:

  • 感谢您的解决方案,但在目的地位置名称显示纬度和经度值时我仍然遇到同样的问题。
  • 你无能为力,如果你想要地址然后反向地理代码,然后在目的地传递文本地址
猜你喜欢
  • 1970-01-01
  • 2013-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-15
  • 1970-01-01
  • 2016-09-08
  • 1970-01-01
相关资源
最近更新 更多