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.
To implement the HERE Mobility Sample App, you will need to use the following development kits:
Name | Description | Documentation |
---|---|---|
Map Kit | Provides map services such as geo-coding | https://heremobilitydevelopers.github.io/Here-Mobility-SDK-iOS/HereSDKMapKit |
Demand Kit | Allows passengers (demand-side users) to request and book rides | https://heremobilitydevelopers.github.io/Here-Mobility-SDK-iOS/HereSDKDemandKit |
To use the HERE Mobility SDK, you'll need App ID key and App secret key values. To request these credentials, contact us at [email protected].
In a Bash command window, clone the Sample App Git repository as follows:
# Clone this repository
$ git clone https://github.com/HereMobilityDevelopers/Here-Mobility-SDK-iOS-SampleApp.git
# Run pod update
$ pod update
# Set HereMobilitySDKAppId & HereMobilitySDKAppSecret at Info.plist
# Run sampleApp.xcworkspace
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.
func requestGeocodeResults(query: String) {
guard let lastLocation = lastLocation else { return }
mapService.geocodeQuery(query,
forlocation: lastLocation,
resultType: .place,
countryCode: "") { [weak self] (results, error) in
if error != nil {
// handle error
}
else {
// handle geocode result
}
}
}
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.
if let originGeocodeResult = self.originGeocodeResult, let destinationGeocodeResult = self.destinationGeocodeResult{
let startLocation = CLLocation(latitude: originGeocodeResult.center.latitude , longitude: originGeocodeResult.center.longitude)
let endLocation = CLLocation(latitude: destinationGeocodeResult.center.latitude , longitude: destinationGeocodeResult.center.longitude{
if let routeRequest = HereSDKRouteRequest(points: [startLocation, endLocation]){
mapService.getRoutesWith(routeRequest, andHandler: { [weak self] routes, error in
if (error == nil){
if let firstRoute = routes?.first{
// handle route
}
}
else{
// handle error
}
})
}
}
The HERE SDK Demand Kit allows you to request ride offers based on various parameters.
mapService.getAddressData(withAddressId: originAddressId, andHandler: { (addressData, error) in
if (error != nil){
// handle error
}
else{
// handle address data
}
})
let originDemandLocation = HereSDKDemandLocation(location: originCLLocation,
address: originAddressData,
freeText: nil)
let destinationDemandLocation = HereSDKDemandLocation(location: destinationCLLocation,
address: destinationAddressData,
freeText: nil)
return HereSDKDemandRoute(pickupLocation: originDemandLocation,
destinationLocation: destinationDemandLocation)
HereSDKDemandRideOffersRequest.rideOffers(with: demandRoute,
constraints: nil,
prebookPickupTime: nil,
priceRange: nil,
sortType: .unknown,
passengerNote: "",
transitOptions: demandTransitOptions)
HereSDKDemandManager.shared.requestRide(rideRequest) { [weak self] offers, error in
if (error != nil){
// handle error
}
if let offers = offers{
// handle offers
}
}
switch offer.getTransitType() {
case .taxi:
// handle demand ride offer
case .publicTransport:
// handle public transport
}
Once you have a ride offer, you can book the ride.
RideStatusServiceImpl.shared()
HereSDKDemandPassenger(name: "Passenger name",
phoneNumber: "+9721234567",
photoUrl: "",
email: "")
let demandRideRequest = HereSDKDemandRideRequest(offerId: rideOffer.offerId,
passengerDetails: passengerDetails)
HereSDKDemandManager.shared.createRide(with: demandRideRequest) { [weak self] ride, error in
if error != nil {
//handle error
}
else{
//handle booked ride
}
}
The HERE SDK Demand Kit allows you register for updates on a ride's progress, including its status, location and ETA.
RideStatusServiceImpl.shared().addObserver(self, for: rideId)
extension SDKRideStatusViewController: RideStatusObserver {
func didUpdateStatus(for ride: HereSDKDemandRide) {
// handle ride updates statuses
}
func didUpdateLocation(_ location: HereSDKDemandRideLocation, for ride: HereSDKDemandRide) {
//handle ride location update
}
To get help with the HERE Mobility SDK, contact our support team at [email protected]