【问题标题】:Google maps does not show route properly if Google maps is not running already如果 Google 地图尚未运行,则 Google 地图无法正确显示路线
【发布时间】:2016-11-22 11:06:50
【问题描述】:

我正在我的应用程序中实现功能,用户可以在其中看到从他当前位置到目的地位置的路线。当用户点击按钮时,我会像这样打开 Google 地图应用程序

if UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!) {

            let urlStr = String(format: "comgooglemaps://?saddr=&daddr=%f,%f&directionsmode=driving&zoom=14", lat, lng)
            let url = NSURL(string:urlStr)!
            UIApplication.sharedApplication().openURL(url)

}

saddr 参数留空,以便 Google 地图可以选择我当前的位置。但如果谷歌地图尚未运行,谷歌地图不会首次显示路线。它只显示我当前的位置,并出现一个加载圈。但如果 Google 地图正在运行并且我打开地图以显示路线,它就可以正常工作。

有人遇到过同样的问题吗?任何帮助将不胜感激。谢谢

【问题讨论】:

  • 我在 iOS 14 上遇到了同样的问题,你有什么更新吗?

标签: ios swift google-maps


【解决方案1】:

让 camera = GMSCameraPosition.cameraWithLatitude(0, longitude:-165, zoom:2) 让 mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)

let path = GMSMutablePath()
path.addLatitude(-33.866, longitude:151.195) // Sydney
path.addLatitude(-18.142, longitude:178.431) // Fiji
path.addLatitude(21.291, longitude:-157.821) // Hawaii
path.addLatitude(37.423, longitude:-122.091) // Mountain View

let polyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor.blueColor()
polyline.strokeWidth = 5.0
polyline.map = mapView

self.view = mapView

}

【讨论】:

  • 感谢@raheem 的回答。但是这段代码在应用程序中绘制地图,但我说的是作为单独的应用程序打开谷歌地图。
  • UIApplication *app = [UIApplication sharedApplication]; NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"comgooglemaps://?saddr=%f,%f&daddr=%f,%f", self.startLocation.latitude, self.startLocation.longitude, self.destinationLocation .latitude, self.destinationLocation.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [app openURL:url];
  • 尝试为源和目标分别传递纬度经度。
猜你喜欢
  • 2012-03-07
  • 2014-07-15
  • 2020-06-23
  • 1970-01-01
  • 1970-01-01
  • 2014-04-04
  • 1970-01-01
  • 2012-02-16
  • 1970-01-01
相关资源
最近更新 更多