Skip to content

Getting Started

PavelTychinin edited this page Dec 18, 2024 · 16 revisions

To start using Navigation library in your project you should do the following steps.

Step 1

Register on http://locations.navigine.com, create a location and get your personal security key in the profile (it has the form 16 hexadecimal digits: XXXX-XXXX-XXXX-XXXX).

Step 2

Use jitpack to integrate SDK to your project jitpack page. OR Download "libnavigine.aar" and add it to the Android project.

Step 3

Initialize Navigation library in your code before any other library functions are called:

// Initialize Navigine library
Navigine.initialize(Context);

// Set user hash and server before getting the instance of [[NavigineSdk|class-NavigineSdk]]

NavigineSdk mNavigineSdk = NavigineSdk.getInstance();
mNavigineSdk.setUserHash(mUserHash); // your user hash from the server
mNavigineSdk.setServer(mLocationServer); // your server url (by default `https://ips.navigine.com`)

If mNavigineSdk is null than library is not initialized and cannot be used. This generally happens in one of the following cases:

  • Android SDK version is less than 21;
  • Android device doesn't support Bluetooth 4.0;
  • CPU architecture is not supported yet.
Step 4

Get instance of LocationManager, set LocationListener and download a location archive from the server using the following (or similar) code:

LocationManager mLocationManager = mNavigineSdk.getLocationManager();
mLocationManager.addLocationListener(new LocationListener() {
  @Override
  public void onLocationLoaded(Location location) {
     // do smth with location
  }

  @Override
  public void onDownloadProgress(int progress, int total) {
     // do smth with location download progress
  }

  @Override
  public void onLocationFailed(Error error) {
     // do smth if error occurs during downloading location
  }
});

mLocationManager.setLocation(/* your location id */);
Step 5

If location archive was successfully loaded you can start navigation (see NavigationManager for details). You can set the LocationView and it will display your position, or you can use NavigationManager and get updates about your position through PositionListener.

NavigationManager mNavigationManager = mNavigineSdk.getNavigationManager();
mNavigationManager.addPositionListener(new PositionListener() {
  @Override
  public void onPositionUpdated(Position position) {
     // do smth with position
  }

  @Override
  public void onPositionError(Error error) {
     // do smth if error occurs during downloading location
  }
});
Step 6

Add following code in layout xml file

    <com.navigine.view.LocationView
        android:id="@+id/location_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

Step 7

Use LocationView in your code

public class NavigationFragment extends Fragment {
    LocationView mLocationView;
    LocationManager mLocationManager
    IconMapObject mPosition = null;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mLocationView = view.findViewById(R.id.location_view);
        mPosition = locationView.getLocationViewController().addIconMapObject();
        mPosition.setSize(30, 30);
        mPosition.setBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.blue_dot));

        mLocationManager = mNavigineSdk.getLocationManager();
        mLocationManager.addLocationListener(new LocationListener() {
          @Override
          public void onLocationLoaded(Location location) {
             locationView.getLocationViewController().setSublocationId(location.getSublocations().get(0).getId());
          }

          @Override
          public void onDownloadProgress(int progress, int total) {
             // do smth with location download progress
          }

          @Override
          public void onLocationFailed(Error error) {
             // do smth if error occurs during downloading location
          }
      });
    }
}
Clone this wiki locally