Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-15527] Geolocation Module #183

Merged
merged 8 commits into from
Jan 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,4 @@ Ti.UI.createSearchBar = function(args) {
Ti.API.error('Ti.UI.createSearchBar() NOT SUPPORTED IN BB10, using textField instead');
return Ti.UI.createTextField(args);
}
Ti.Geolocation.getCurrentPosition = function(_callback) {
function _onlocation(e) {
_callback(e);
setTimeout(function(){
Ti.Geolocation.removeEventListener('location', _onlocation);
}, 100);
}
Ti.Geolocation.addEventListener('location', _onlocation);
}
Titanium = Ti;
54 changes: 0 additions & 54 deletions src/tibb/GeolocationSession.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions src/tibb/GeolocationSession.h

This file was deleted.

60 changes: 60 additions & 0 deletions src/tibb/Modules/Geolocation/TiCompassSession.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#include "TiCompassSession.h"
#include "TiGeolocationModule.h"
#include <QtSensors/QCompassReading>

TiCompassSession::TiCompassSession(TiGeolocationModule* module) : _module(module) {

_compass = new QCompass(this);
_compass->setAxesOrientationMode(QCompass::FixedOrientation);

QObject::connect(_compass,
SIGNAL(readingChanged()),
this,
SLOT(onReadingChanged()));
_compass->start();

}

TiCompassSession::~TiCompassSession() {
// TODO Auto-generated destructor stub
}

void TiCompassSession::setCallbackFunction(Ti::TiValue value)
{
_callbackFunction = Ti::TiValue(value.toJSValue());
}

void TiCompassSession::onReadingChanged()
{
QCompassReading *reading = _compass->reading();
Ti::TiEventParameters eventParams;
eventParams.addParam("heading", (int)reading->azimuth());
eventParams.addParam("calibration", (int)reading->calibrationLevel());
_module->fireEvent("heading", eventParams);
if(_callbackFunction.isValid())
{
_compass->stop();
Ti::TiValue headingValue;
headingValue.setNumber((int)reading->azimuth());

Ti::TiValue calibrationValue;
calibrationValue.setNumber((int)reading->calibrationLevel());

QMap<QString, Ti::TiValue> map;
map.insert("heading", headingValue);
map.insert("calibration", calibrationValue);

Ti::TiValue val;
val.setMap(map);

_callbackFunction.callFunction(_module, val);
deleteLater();
}
}
33 changes: 33 additions & 0 deletions src/tibb/Modules/Geolocation/TiCompassSession.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#ifndef TICOMPASSSESSION_H_
#define TICOMPASSSESSION_H_

#include <QObject>
#include <QtSensors/QCompass>
#include "TiCore.h"

using namespace QtMobility;

class TiGeolocationModule;
class TiCompassSession : public QObject
{
Q_OBJECT;
public:
TiCompassSession(TiGeolocationModule*);
virtual ~TiCompassSession();
void setCallbackFunction(Ti::TiValue);
public slots:
void onReadingChanged();
private:
QCompass* _compass;
TiGeolocationModule *_module;
Ti::TiValue _callbackFunction;
};

#endif /* TICOMPASSSESSION_H_ */