How do i open Google Maps for directions using coordinates on the iphone

后端 未结 7 1902
礼貌的吻别
礼貌的吻别 2020-12-12 18:29

I am using UIMapView to display locations on the iPhone. I want to do a directions from current location to the location of interest, I don\'t think its possible using MapKi

相关标签:
7条回答
  • 2020-12-12 19:10

    Use bellow code for both google and apple maps in Swift 3 -

    if UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!)
            {
                let urlString = "http://maps.google.com/?daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&directionsmode=driving"
    
                // use bellow line for specific source location
    
                //let urlString = "http://maps.google.com/?saddr=\(sourceLocation.latitude),\(sourceLocation.longitude)&daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&directionsmode=driving"
    
                UIApplication.shared.openURL(URL(string: urlString)!)
            }
            else
            {
                //let urlString = "http://maps.apple.com/maps?saddr=\(sourceLocation.latitude),\(sourceLocation.longitude)&daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&dirflg=d"
                let urlString = "http://maps.apple.com/maps?daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&dirflg=d"
    
                UIApplication.shared.openURL(URL(string: urlString)!)
            }
    
    0 讨论(0)
提交回复
热议问题