1

我正在尝试构建一个指南针,指向地图上带有 Titanium 的注释。我已经成功地用 Titanium 中的指南针功能构建了一个普通的指南针。

我无法从该位置使指南针指向正确的方向。有没有人有脚本或示例有效?

    if (Titanium.Geolocation.hasCompass){

    var transform = Ti.UI.create2DMatrix();

    // Settings
    Titanium.Geolocation.showCalibration = true;
    Titanium.Geolocation.headingFilter = 0;

    Ti.Geolocation.getCurrentHeading(function(e){

        if (e.error){
            Titanium.API.info("error: " + e.error);
            return;
        }

        var animationNorth = Titanium.UI.createAnimation({
            transform   : transform.rotate(e.heading.trueHeading),
            duration    : 50
        });

        // Rotate image to north
        compassNorth.animate(animationNorth);

        headingLabel.setText('geo - current heading: ' + e.heading.trueHeading);
    });

    Titanium.Geolocation.addEventListener('heading', function(e){

        if (e.error){
            Titanium.API.info("error: " + e.error);
            return;
        }

        var animationNorth = Titanium.UI.createAnimation({
            transform   : transform.rotate(e.heading.trueHeading),
            duration    : 50
        });

        // Rotate image to north
        compassNorth.animate(animationNorth);

        headingLabel.setText('geo - current heading: ' + e.heading.trueHeading);
    });

} else {
    headingLabel.setText("No Compass on device");
}
4

0 回答 0