# Example code

Source: [https://docs.qualcomm.com/doc/80-PK177-134/topic/precise_gtp_example_code.html](https://docs.qualcomm.com/doc/80-PK177-134/topic/precise_gtp_example_code.html)

## Java

**Required imports**

    private IQesdk mQesdkManager;
    private PRECISE_GTPManager preciseGtpManager;Copy to clipboard

**Create the QESDK Manager instance**

    IQesdk mQesdkManager = IQesdk.createInstance(this);Copy to clipboard

**Create Precise GTP Manager instance**

    PRECISE_GTPManager preciseGtpManager = new PRECISE_GTPManager(qesdkManager); 
    int status = preciseGtpManager.init([String license],(opcodes, subsystem)->{
    // Location Init Callback handle
    });Copy to clipboard

**Send request to start location updates**

    preciseGtpManager.requestNetworkLocationUpdates(minIntervalMillis,location->{
    // Location Report Callback handle
    });Copy to clipboard

**Send request to stop location updates**

    preciseGtpManager.removeNetworkLocationUpdates()Copy to clipboard

**Send request to start passive location updates**

    preciseGtpManager.requestPassiveNetworkLocationUpdates(location->{
    // Location Report Callback handle
    }));Copy to clipboard

**Send request to stop passive location updates**

    preciseGtpManager.removePassiveNetworkLocationUpdates();Copy to clipboard

**Request user consent for network positioning**

    preciseGtpManager.setUserConsent(consentAccepted);Copy to clipboard

**Register location capability callback**

    preciseGtpManager.registerLocationCapabilitiesCallback(isFeatureSupported->{ 
    // Feature Supported Callback handle
    });Copy to clipboard

## Native

**Required includes.**

    #include "qesdk_ndk.h"
    #include "qesdk_precise_gtp_manager.h"Copy to clipboard

**Create Precise GPT Manager instance**

    PRECISE_GTPManager *preciseGtpManager = new PRECISE_GTPManager();
    int ret = preciseGtpManager->init(licenseStr, 
                                      license_length,
                                      [](uint32_t opcodes, uint32_t *subsystems) {
    // Callback to handle init events
    });Copy to clipboard

**Send request to start location updates**

    precise_gtp_LocationStatus ret = precise_gtp_LocationStatus::QESDK_GENERIC_FAILURE;
    qesdk_transaction_status qesdk_ndk_response = preciseGtpManager->requestNetworkLocationUpdates(min_interval_millis, [](precise_gtp_Location location) { // Location Report Callback handle }, ret); 
    if(qesdk_ndk_response.is_ok()){
      // Use the ret value
    } else {
      // Can get error code by get_error_code() 
    }Copy to clipboard

**Send request to stop location updates**

    qesdk_ndk_response = preciseGtpManager->removeNetworkLocationUpdates(ret); 
    if(qesdk_ndk_response.is_ok()){
      // Use the ret value
    } else {
      // Can get error code by get_error_code() 
    }Copy to clipboard

**Send request to start passive location updates**

    qesdk_ndk_response = preciseGtpManager->requestPassiveNetworkLocationUpdates( [] (precise_gtp_Location location) { // Location Report Callback handle }), ret); 
    if(qesdk_ndk_response.is_ok()){
      // Use the ret value
    } else {
      // Can get error code by get_error_code() 
    }Copy to clipboard

**Send request to stop passive location updates**

    qesdk_ndk_response = preciseGtpManager->removePassiveNetworkLocationUpdates(ret); 
    if(qesdk_ndk_response.is_ok()){
      // Use the ret value
    } else {
      // Can get error code by get_error_code() 
    }Copy to clipboard

**Request user consent for network positioning**

    qesdk_ndk_response = preciseGtpManager->setUserConsent(consent_accepted, ret); 
    if(qesdk_ndk_response.is_ok()){
      // Use the ret value
    } else {
      // Can get error code by get_error_code() 
    }Copy to clipboard

**Register location capability callback**

    qesdk_ndk_response = preciseGtpManager->registerLocationCapabilitiesCallback([](bool isFeatureSupported){
    // Feature Supported Callback handle }, ret); 
    if(qesdk_ndk_response.is_ok()){
      // Use the ret value
    } else {
      // Can get error code by get_error_code() 
    }Copy to clipboard

**Parent Topic:** [Precise GTP](https://docs.qualcomm.com/doc/80-PK177-134/topic/precise_gtp.html)

Last Published: Nov 14, 2024

[Previous Topic
Location](https://docs.qualcomm.com/bundle/publicresource/80-PK177-134/topics/precise_gtp_location_report.md) [Next Topic
Robust location](https://docs.qualcomm.com/bundle/publicresource/80-PK177-134/topics/robust_location.md)