Reputation: 27
I'm currently making an app that includes a feature for the user to be able to take an Uber home with the click of a button. I learned that deeplinking does the trick. However, I'm not quite sure how I can obtain the latitude and longitude of the user's home. I would greatly appreciate your help with regards to this matter. Have a nice day. Shown is the method to get the uri for deeplinking.
private String getUberUri() {
StringBuilder uberUri = new StringBuilder("uber://?action=setPickup&client_id=LNC3kco5fh8RGBhJF9hJtqRKPSPCxMt-");
uberUri.append("&pickup=my_location");
uberUri.append("&dropoff[nickname]=").append(placeBundle.getString("NAME", "Dropoff"));
uberUri.append("&dropoff[latitude]=").append(placeBundle.getDouble("PLACE_LAT"));
uberUri.append("&dropoff[longitude]=").append(placeBundle.getDouble("PLACE_LNG"));
return uberUri.toString();
}
This is the Button's onClickListener:
Button uberButton = (Button) findViewById(R.id.uberButton);
uberButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isPackageInstalled("com.ubercab")) {
Intent uberIntent = new Intent();
uberIntent.setData(Uri.parse(getUberUri()));
mActivity.startActivity(uberIntent);
} else {
Toast.makeText(mActivity, "Please install Uber", Toast.LENGTH_SHORT).show();
Uri uberPlayStoreUri = Uri.parse(
"https://play.google.com/store/apps/details?id=com.ubercab");
Intent uberIntent = new Intent(Intent.ACTION_VIEW, uberPlayStoreUri);
uberIntent.setPackage("com.android.vending");
mActivity.startActivity(uberIntent);
}
}
}
);
Upvotes: 0
Views: 70
Reputation: 857
There are two Uber API endpoints available to set work and home location and to get them.
If you want to set your home or work address you need to use: "PUT /v1.2/places/{place_id}" endpoint. Where "place_id" can be home and work.
To get your your predefined locations you need to use: "GET /v1.2/places/{place_id}"
Example request :
curl -H 'Authorization: Bearer ' \ -H 'Accept-Language: en_US' \ -H 'Content-Type: application/json' \ 'https://api.uber.com/v1.2/places/work'
Response:
{ "address": "685 Market St, San Francisco, CA 94103, USA" }
The only limitation is you will need to parse address to obtain "end_latitude" and "end_longitude".
There is also option when you do your ride request to use following parameters:
"start_place_id": "home", "end_place_id": "work"
Upvotes: 1