Display ETA and estimated money option for my “Ride there with Uber” button

谁都会走 提交于 2019-12-23 18:41:51

问题


I have integrated a "Ride there with Uber" button to my app. I feel, it would be more convenient for the users, if i displayed the ETA and estimated pricing for the destination. How may I achieve this? I am following this guide as of now : https://github.com/uber/rides-ios-sdk

It seems like I need, some kind of product ID to be able to achieve this. But how do i get it?

Made some progress, I got my self the product id, but it still doesn't work. Here is my current code:


回答1:


Button will Deeplink into the Uber App and will simply open up the app. In order to see real-time fare estimates and pickup ETA information you will need to pass additional parameters to it. The Ride Request Button can accept optional parameters to pre-load some information into the ride request. You can see how to do it in the Uber documentation. Also this is explained here on the GitHub.




回答2:


I got the solution || ViewController.swift

var button = RideRequestButton()


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let builder = RideParametersBuilder()
    let pickupLocation = CLLocation(latitude: 37.787654, longitude: -122.402760)
    let dropoffLocation = CLLocation(latitude: 37.775200, longitude: -122.417587)
    builder.pickupLocation  = pickupLocation
    builder.dropoffLocation = dropoffLocation
    builder.dropoffNickname = "Somewhere"
    builder.dropoffAddress  = "123 Fake St."

    var productID = ""
    let ridesClient = RidesClient()
    ridesClient.fetchProducts(pickupLocation: pickupLocation) { (product, response) in
        productID = product[1].productID!
        builder.productID = productID
    }

    ridesClient.fetchPriceEstimates(pickupLocation: pickupLocation, dropoffLocation: dropoffLocation) { (price, response) in
        print(price[0].estimate!)

        self.button.rideParameters = builder.build()
        self.button.loadRideInformation()
    }
    button.center = self.view.center
    self.view.addSubview(button)
}

Also, do make little change into UberRides->RideRequestButton.swift`

override public func setContent() { super.setContent()

    uberMetadataLabel.numberOfLines = 0
    uberMetadataLabel.sizeToFit()`

and

private func setMultilineAttributedString(title: String, subtitle: String = "", surge: Bool = false) {
    let metadataFont = UIFont(name: "HelveticaNeue-Regular", size: 10) ?? UIFont.systemFont(ofSize: 10)

and last one change width (+30) of uberMetadataLabel below like

override public func sizeThatFits(_ size: CGSize) -> CGSize

var width: CGFloat = 4*horizontalEdgePadding + imageLabelPadding + logoSize.width + titleSize.width+30

If any query please comment here




回答3:


The issue is kind of funny and I think uber should change there documentation. You need to fetch products and price estimates and then loadRideInformation(). Guess what! the default button width is smaller than required. (Don't forget to add both the ClientID and ServerToken)

        let pickupLocation = CLLocation(latitude:23.782221 , longitude:90.395263 )
        let dropoffLocation = CLLocation(latitude: 23.8116404, longitude: 90.4279034)

        let uberClient = RidesClient()
        let builder = RideParametersBuilder()
        let uberReqButton = RideRequestButton()
        uberReqButton.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: uberReqButton.frame.height)
        self.uberview.addSubview(uberReqButton)
        SKActivityIndicator.show()

        uberClient.fetchProducts(pickupLocation: pickupLocation, completion: { (Products, _) in
            if (Products[0].productID != nil){
                uberClient.fetchPriceEstimates(pickupLocation: pickupLocation, dropoffLocation: dropoffLocation) { (priceEstimates, Response) in

                    SKActivityIndicator.dismiss()// used for loading animation, ignore if not not needed
                    builder.pickupLocation = pickupLocation
                    builder.pickupAddress = "pickup Address"
                    builder.pickupNickname = "pickup nick"
                    builder.dropoffLocation = dropoffLocation
                    builder.dropoffAddress = "drop Address"
                    builder.dropoffNickname = "drop nick"
                    builder.productID = Products[0].productID

                    uberReqButton.rideParameters = builder.build()

                    DispatchQueue.main.async {
                        uberReqButton.loadRideInformation()
                    }
                }
            }
        })


来源:https://stackoverflow.com/questions/46935061/display-eta-and-estimated-money-option-for-my-ride-there-with-uber-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!