Sanket Ray
Sanket Ray

Reputation: 1141

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

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?

enter image description here

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

enter image description here

Upvotes: 3

Views: 798

Answers (3)

EarlySun
EarlySun

Reputation: 185

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

Upvotes: 0

Kanhaiya Sharma
Kanhaiya Sharma

Reputation: 1038

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

Upvotes: 1

Sasa Jovanovic
Sasa Jovanovic

Reputation: 857

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.

Upvotes: 1

Related Questions