- 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.
Create an account in map.ir then create a project and get your API_KEY : https://corp.map.ir/registration/
Add this line in dependencies scope in your project's app.gradle :
implementation 'ir.map.tracker:tracker:$latest_version'
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> // For receive location updates
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> // For read device imei
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> // For making LiveService run in forground if you want use SDK's service
<service
android:name="ir.map.tracker.PublisherService"
android:enabled="true" />
3.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 MISSING_API_KEY:
// Provided access token is missing or wrong
break;
case MISSING_TRACK_ID:
// Missing track_id
break;
case MISSING_CONTEXT:
// Missing context
break;
}
}
@Override
public void onLiveTrackerDisconnected() {
// Tracker disconnected
}
});
@Override
protected void onResume() {
if (publisher != null)
publisher.onResume();
super.onResume();
}
@Override
protected void onPause() {
if (publisher != null)
publisher.onPause();
super.onPause();
}
publisher.start(interval); // interval is in miliseconds and should be at least 1000
publisher.stop();
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> // For read device imei
2.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 MISSING_API_KEY:
// Provided access token is missing or wrong
break;
case MISSING_TRACK_ID:
// Missing track_id
break;
case MISSING_CONTEXT:
// Missing context
break;
}
}
@Override
public void onLiveTrackerDisconnected() {
Toast.makeText(MainActivity.this, "onLiveTrackerDisconnected", Toast.LENGTH_SHORT).show();
}
});
subscriber.start();
subscriber.stop();
Clone project and run subscriber_sample or puvlisher_sample modules seperatly Put your API_KEY in project whenever it needs
Contributions are very welcome 🙌
License is available in LICENSE file.