HERE Mobility offers a mobility platform solution to transportation service providers, businesses, and consumers. The platform consists of the HERE Mobility Marketplace and SDK packages.
The HERE Mobility Marketplace is a "broker" between transportation suppliers and consumers, which matches up ride requests with ride offers. The HERE Mobility SDK enables developers to create apps with a variety of mobility features, while connecting to the HERE Mobility Marketplace.
The Here Mobility sample app (described below) presents a simple workflow for adding a variety of mobility services to your app.
This repository contains the Sample application showing the use of the HERE Mobility SDK for Android.
To use the HERE Mobility SDK, you'll need App ID key and App secret key values. To get new app keys, sign up first to Here Mobility Developer Zone and then register your app using the app bundle id/package name.
- Clone this repository.
- Replace App Key and App Secret in the
here_mobility_app_key.xml
. - Open it in Android Studio and run the app.
Here is an overview of the workflow for booking a ride and monitoring its progress, using the HERE Mobility SDK. Click on a step name to go to its corresponding code example.
Step | Description |
---|---|
Forward geocoding | Retrieve the geo-location for an address or place name |
Get the ride route | Get the ride's route, based on its start and end locations |
Get ride offers | Get ride offers from public or private ride suppliers |
Book a ride | Book one of the ride offers received |
Register for ride updates | Register for updates about the ride's progress |
The HERE SDK Map Kit supports forward geocoding and reverse geocoding. Forward geocoding is the conversion of a street address or place name to a geo-location (latitude/longitude pair). Reverse geo-coding is the conversion of a geo-location (latitude/longitude pair) to addresses or place names near the given geo-location.
The following code snippet shows how to query for a geocoding result, based on a query string and location coordinates.
//Create forward geocoding request.
GeocodingRequest geocodingRequest = GeocodingRequest.newForwardRequest(
query,
location, //The location around which to search for results.
countryCode, //ISO 3166 alpha 3 country to code used filter results.
languageCode, //ISO 639-1 language code for the preferred language of the results
resultTypes); // The result types to obtain.
//send the request.
ResponseFuture<GeocodingResponse> autocompleteResponse =
autocompleteClient.geocode(geocodingRequest);
//register listener for updates.
autocompleteResponse.registerListener(geocodingResponseResponseListener);
In the HERE SDK Map Kit, routes are represented by "polylines", which are lines composed of multiple, connected straight-line segments. A route's polyline originates from the ride's start location and ends at the ride's destination location, optionally going through additional "waypoint" locations.
The following code snippet shows how to retrieve routes with the given start and end locations.
//Initialize RouteClient.
RoutingClient routingClient = RoutingClient.newInstance();
//Request route calculation between pickup to destination.
RouteRequest routeRequest = RouteRequest.create(pickup, destination);
//Route Request, register to updates listener.
routingClient.
requestRoute(routeRequest).
registerListener(routeListener);
The HERE SDK Demand Kit allows you to request ride offers based on various parameters.
//Initialize RouteClient.
RoutingClient routingClient = RoutingClient.newInstance();
//Request route calculation between pickup to destination.
RouteRequest routeRequest = RouteRequest.create(pickup, destination);
//Route Request, register to updates listener.
routingClient.
requestRoute(routeRequest).
registerListener(routeListener);
//RideOffersRequest builder.
RideOffersRequest.Builder rideOfferBuilder = RideOffersRequest.builder()
.setConstraints(bookingConstraints)
.setRideWaypoints(rideWaypoints);
//set pre-book time, default is now.
if (preBookTime != null) {
rideOfferBuilder.setPrebookPickupTime(preBookTime);
}
RideOffersRequest rideOffersRequest = rideOfferBuilder.build();
//Request ride offers.
ResponseFuture<List<RideOffer>> offersFuture = demandClient.getRideOffers(rideOffersRequest);
//Register offers future listener.
offersFuture.registerListener(rideOffersFutureListener);
offer.accept(new RideOffer.Visitor<Void>() {
@Override
public Void visit(@NonNull TaxiRideOffer taxiRideOffer) {
//Use taxi ride offer.
return null;
}
@Override
public Void visit(@NonNull PublicTransportRideOffer publicTransportRideOffer) {
//Use public transport ride offer
return null;
}
});
Once you have a ride offer, you can book the ride.
PassengerDetails passengerDetails = PassengerDetails.builder()
.setName(name)
.setPhoneNumber(phone).build();
CreateRideRequest.Builder rideRequest = CreateRideRequest
.builder(taxiRideOffer.getOfferId(), passengerDetails);
//Request to book a ride.
ResponseFuture<Ride> rideRequestFuture = demandClient.createRide(rideRequest.build());
//Register for ride request updates.
rideRequestFuture.registerListener(rideFutureListener);
The HERE SDK Demand Kit allows you register for updates on a ride's progress, including its status, location and ETA.
DemandClient demandClient = DemandClient.newInstance();
DemandClient.RideUpdateListener listener = new DemandClient.RideUpdateListener() {
@Override
public void onRideStatusChanged(@NonNull Ride changedRide, @NonNull RideStatusLog rideStatusLog) {
}
@Override
public void onRideLocationChanged(@NonNull Ride ride, @NonNull RideLocation rideLocation) {
}
@Override
public void onErrorOccurred(@NonNull Throwable throwable) {
}
};
demandClient.registerToRideUpdates(rideId,listener);
To get help with the HERE Mobility SDK, contact our support team at [email protected]