/** * Called from PhoneGapMessageHandler on EVENT_TYPE_LOCATION. */ void PhoneGapSensors::sendLocationData(const MAEvent& event) { MALocation& loc = *(MALocation*)event.data; char result[1024]; bool keepCallBack; // This is used to prevent PhoneGap from deleting the callback after // receiving the first result. if (mLocationWatchStarted) { keepCallBack = true; } else { keepCallBack = false; // Stop it after first data since we are not in watched mode. maLocationStop(); } // Call the PhoneGap function, can call the commandResult function too. sprintf(result, "{coords:{" "latitude:%f," "longitude:%f," "altitude:%f," "accuracy:%f," "altitudeAccuracy:%f," "heading:%f," "speed:%f" "}}", loc.lat, loc.lon, loc.alt, loc.horzAcc, loc.vertAcc, 0.0, // MoSync Location API does not support heading 0.0 // MoSync Location API does not support speed ); mMessageHandler->callSuccess( mLocationWatchCallBack, PHONEGAP_CALLBACK_STATUS_OK, result, keepCallBack); }
/** * Implementation of sensor API:s exposed to JavaScript. * @return true if message was handled, false if not. */ void PhoneGapSensors::handleMessage(JSONMessage& message) { // Accelerometer request from PhoneGap if ((message.getParam("service") == "Accelerometer")) { if (message.getParam("action") == "getAcceleration") { processAcelerometerRequest( message.getParam("PhoneGapCallBackId"), false); //stop Accelerometer after the first run } else if (message.getParam("action") == "start") { processAcelerometerRequest( message.getParam("PhoneGapCallBackId"), true); // Keep the Accelerometer running } else if (message.getParam("action") == "stop") { maSensorStop(SENSOR_TYPE_ACCELEROMETER); mAccelerometerWatchStarted = false; } } // GeoLocation request from PhoneGap else if (message.getParam("service") == "GeoLocation") { if (message.getParam("action") == "addWatch") { processLocationRequest( message.getParam("PhoneGapCallBackId"), true); } else if (message.getParam("action") == "getLocation") { processLocationRequest( message.getParam("PhoneGapCallBackId"), false); //stop GPS after the first run } else if (message.getParam("action") == "clearWatch") { maLocationStop(); mLocationWatchStarted = false; } } // Compass request from PhoneGap else if (message.getParam("service") == "Compass") { if(message.getParam("action") == "getHeading") { processCompassRequest( message.getParam("PhoneGapCallBackId"), false); //stop Sensor after the first run } // Cordova 2.3.0 doesn't use Compass.startWatch /* else if (message.getParam("action") == "startWatch") { processCompassRequest( message.getParam("PhoneGapCallBackId"), true); // Keep the Compass running } */ else if (message.getParam("action") == "stopHeading") { maSensorStop(SENSOR_TYPE_COMPASS); mAccelerometerWatchStarted = false; } } }
SMV::~SMV() { maLocationStop(); delete engine, mScreen, mList; }