Find Devices (Advanced)

The plug-in can communicate with one or more connected Garmin devices. The findDevices method discovers what devices are visible, as well as the types of devices connected.

The two steps typical of handling call-back communication with the plugin are:

1. Create a listener class with call-back methods of interest. Note all call-back methods are prefixed with on, in this case the method is onFinishFindDevices:

var listener = Class.create();
listener.prototype = {
    onFinishFindDevices: function(json) {
    ... }}

2. Register an instance of the listener class with the control:

control.register( new listener() );

Example

    var listener = Class.create();
    listener.prototype = {
        initialize: function() { },
        onFinishFindDevices: function(json) {
            var devices = json.controller.getDevices();
            var str = "Found: "+devices.length+" devices: ";
            for( var i=0; i < devices.length; i++ ) {
                str += devices[i].getDisplayName()+", ";
             alert(str);
        }
    }
    function load() { //called from the html page onload event
        control = new Garmin.DeviceControl();
        control.register(new listener());
        var unlocked = control.unlock("http://mydomain.com/","yourKeyGoesHere");
        control.findDevices();
    }

Complete cut-and-paste example

1. Create a file called device.html and paste the code below.
2. Replace ‘http://mydomain.com/’ with your website base URL.
3. Replace ‘yourKeyGoesHere’ with key provided by Garmin for your website base URL.
4. Load in your browser.
5. Plug in a GPS device using a USB cable and turn it on
6. Click on the Load Devices button (it may take a few seconds to find devices).
















 


    

Auto Load Plugin

Developer Resources