- Map.ir Live Tracker uses MQTT protocol which has low data usage.
- Easy configuration.
- Complete and expressive documentation.
- You can use both Java and Kotlin languages.
The example applications are the best way to see MapirLiveTracker in action. Simply clone and open app in Android Studio.
Add this line in dependencies scope in your project's app.gradle :
implementation 'ir.map.tracker:tracker:$latest_version'1.Create publisher object and use static method getLiveTracker to initialize object to work with it :
Publisher publisher = Publisher.getLiveTracker(context, API_KEY, track_id, true, new TrackerEvent.PublishListener() {
@Override
public void publishedLocation(Location location) {
// Each published location
}
@Override
public void onFailure(PublisherError error) {
switch (code) {
case LOCATION_PERMISSION:
// Missing Location permission
break;
case TELEPHONY_PERMISSION:
// Missing Telephony permission
break;
case INITIALIZE_ERROR:
// Something went wrong during sdk initilization
break;
case API_KEY_NOT_AVAILABLE:
// Provided access token is missing or wrong
break;
}
}
@Override
public void onLiveTrackerDisconnected() {
// Tracker disconnected
}
});
publisher.start(INTERVAL); // INTERVAL is in miliseconds and should be at least 1000
1.Create subscriber object and use static method getLiveTracker to initialize object to work with it :
Subscriber subscriber = Subscriber.getLiveTracker(context, API_KEY, track_id, new TrackerEvent.SubscribeListener() {
@Override
public void onLocationReceived(Location location) {
// Recieved location
}
@Override
public void onFailure(SubscriberError error) {
switch (code) {
case TELEPHONY_PERMISSION:
// Missing Telephony permission
break;
case INITIALIZE_ERROR:
// Something went wrong during sdk initilization
break;
case API_KEY_NOT_AVAILABLE:
// Provided access token is missing or wrong
break;
}
}
@Override
public void onLiveTrackerDisconnected() {
Toast.makeText(MainActivity.this, "onLiveTrackerDisconnected", Toast.LENGTH_SHORT).show();
}
});
subscriber.start(); // Start receiving locations
Contributions are very welcome 🙌
License is available in LICENSE file.
