Parking SDK for Android

Getting Started

This guide will show you how to use the AIPARK Android SDK which helps you to integrating the AIPARK API.

Installation

Android Build

AndroidBuild uses the gradle build tool. Just integrate AIPARK Android SDK into your gradle file:

dependencies {
    implementation ('de.aipark.android.sdk:aiparkandroidsdk:2832')
}

Dependencies

The following dependencies are required to run the AIPARK SDK:

  • com.google.android.gms:play-services-maps:16.0.0
  • com.google.android.gms:play-services-location:16.0.0
  • com.google.maps:google-maps-services:0.2.10
  • de.aipark.api:aipark-api:28.32

First Steps

To use the AIPARK SDK, import the package and initialize the AIPARK class.

import de.aipark.android.sdk.AiparkSDK;
AiparkSDK aiparkSDK = new AiparkSDK(getContext(),"YOUR_API_KEY");

Authorization

To ensure that the AIPARK services run properly, you need the following permissions:

  • android.permission.ACCESS_COARSE_LOCATION
  • android.permission.ACCESS_FINE_LOCATION
  • com.google.android.gms.permission.ACTIVITY_RECOGNITION
  • android.permission.WAKE_LOCK
Key Purpose
ACCESS_COARSE_LOCATION/ACCESS_FINE_LOCATION Reason why GPS is used while app is in use
ACTIVITY_RECOGNITION Reason why the activity need to be recognized for the parking position of the user
WAKE_LOCK Reason why the activity need to be able to wake up from background

Request ParkingAreas

To request parking areas, you need to specify a request object. This object contains the tile that you wish to get parking areas from.

Tiles

Tiles represent predefined map areas. To visualize these tiles, you can visit this website Tiles. The tiles you can specify are on zoom level 16 or 15. To convert a coordinate with Latitude/Longitude into a tile you can use a predefined method:

TileMapper.getTileIndexFromLatLng(Point point, int zoom);

The AIPARK API can be accessed with aiparkSDK.getApi(). An example of a request to get parking areas is shown below. This request returns a set of parking areas from the specified tiles.

AiparkSDK aiparkSDK = new AiparkSDK(getContext(),"YOUR_API_KEY");
        aiparkSDK.getApi()
                .getParkingAreasForTile(
                        new GetParkingAreasForTileRequest(
                                TileMapper.getTileIndexFromLatLng(
                                        (new GeometryFactory()).createPoint(new Coordinate(longitude,latitude))
                                )
                        )
                ).subscribe(new Subscriber() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(GetParkingAreasForTileResponse getParkingAreasForTileResponse) {
                for(MapEntry.Entry<Tile,List> entry :
                        getParkingAreasForTileResponse.getTileParkingAreas().getEntryList()){
                    for(ParkingArea parkingArea: entry.getValue()){
                        System.out.println(parkingArea);
                    }
                }
            }
        });

The following API endpoints are available:

  • getParkingAreasForTile
  • getOccupancyForParkingAreas
  • getParkingAreasForTileWithOccupancy
  • getParkingAreasForTileWithOccupancyForPosition
  • getParkingAreasForPosition
  • getParkingAreasForPositionWithOccupancy
  • getParkingAreasForPositionWithOccupancyForPosition
  • getOptimalTrip
  • getLiveParkEvents
  • getChargingStationsForTile
  • getChargingStationsForPosition

Please refer to the developer portal for detailed information on the data structures associated with each endpoint.

The SDK also supplies the last known parking position:

AiparkSDK aiparkSDK = new AiparkSDK(getContext(),"YOUR_API_KEY");

/**
*    Get parking position with a listener,
*    this listener is called with the last known position immediately
*    and with updated parking position afterwards.
**/
aiparkSDK.setOnNewParkingPositionListener(new OnNewParkingPositionListener() {
    @Override
    public void onNewParkingPosition(ParkingPosition parkingPosition) {
        System.out.println(parkingPosition);
    }
});

/**
*    Or you can get the last known position directly.
**/
ParkingPosition parkingPosition = aiparkSDK.getLastKnownParkingPosition();
        System.out.println(parkingPosition);
Updated on November 17, 2018

Was this article helpful?

Related Articles

Bitnami