<rt id="hkid1"></rt>
    <s id="hkid1"><meter id="hkid1"></meter></s>
  1. <rp id="hkid1"><meter id="hkid1"></meter></rp>
    <source id="hkid1"></source>
  2. <ruby id="hkid1"><optgroup id="hkid1"></optgroup></ruby>

    cordova插件- Geolocation

    小編:管理員 251閱讀 2022.09.13

    • 添加插件

    $ cordova plugin add cordova-plugin-geolocation

    • 插件的使用
    • Methods
    • navigator.geolocation.getCurrentPosition
    • navigator.geolocation.watchPosition
    • navigator.geolocation.clearWatch

    2. Example

    function locationClik() {
    
        navigator.geolocation.getCurrentPosition(onSuccess, onError);
    
    }
    
    
    // onSuccess Callback
    // This method accepts a Position object, which contains the
    // current GPS coordinates
    //
    var onSuccess = function(position) {
        alert('Latitude: '          + position.coords.latitude          + '\n' +
                'Longitude: '         + position.coords.longitude         + '\n' +
                'Altitude: '          + position.coords.altitude          + '\n' +
                'Accuracy: '          + position.coords.accuracy          + '\n' +
                'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
                'Heading: '           + position.coords.heading           + '\n' +
                'Speed: '             + position.coords.speed             + '\n' +
                'Timestamp: '         + position.timestamp                + '\n');
    };
    
    // onError Callback receives a PositionError object
    //
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
                'message: ' + error.message + '\n');
    }
    
    ///////////////////////////////////////////////////////////////////////////////////
    
    
    // onSuccess Callback
    //   This method accepts a `Position` object, which contains
    //   the current GPS coordinates
    //
    function onSuccess(position) {
        var element = document.getElementById('geolocation');
        element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
                'Longitude: ' + position.coords.longitude     + '<br />' +
                '<hr />'      + element.innerHTML;
    }
    
    // onError Callback receives a PositionError object
    //
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
                'message: ' + error.message + '\n');
    }
    
    // Options: throw an error if no update is received every 30 seconds.
    //
    
    var watchID;
    function locationTimeClik() {
    
        watchID  = navigator.geolocation.watchPosition(onSuccess, onError, { timeout: 30000 });
    
    }
    
    //////////////////////////////////////////////////////////////
    
    function clearTimeClik() {
    
        navigator.geolocation.clearWatch(watchID);
    }
    復制
    關聯標簽:
    快三群