quick_recipes (779892), страница 56
Текст из файла (страница 56)
The position returnedto the client may be either a GPS position (calculated in the mobiledevice) or a final network position (calculated using the measurementsby a remote server in the network). The position that is calculated first(the GPS position or the final network position) is generally returnedto the client. The final network position may also be returned to theclient after the return of the GPS position.• Cell-Based PositioningLBS obtains a position fix from the network without using GPS. Thisposition fix is sometimes less accurate than that obtained using GPS.A client application cannot directly choose the positioning mode thatis used for its location request. A handset manufacturer may providean LBS ‘control panel’ type of application where the GPS mode can beselected by an end user.
However, for modes that involve the network(Terminal-Based Positioning, Terminal-Assisted Positioning, Hybrid andCell-Based Positioning), it is possible for a network operator to overridethe GPS mode as part of the location request. If a client wants to knowprecisely how a position fix was calculated, this information is availablein the returned position information object.312SYMBIAN C++ RECIPESA typical scenario might be as follows:• Create a session with the location server (LS).• Create a subsession with the LS using default positioning module.• Set required update options.• Issue a location information request.• Get requested data in TPositionInfo variable or handle possibleerrors.• Close the subsession and the session.The code sample below implements this scenario for the simplest case.A production-quality application will not use User::Wait() to receivean asynchronous notification, but uses an active object to handle events.#include <lbs.h>TInt GetPositionInfoL(TPosition& aPos){RPositionServer server;RPositioner positioner;// 1.
Create a session with the location serverUser::LeaveIfError(server.Connect());CleanupClosePushL(server);// 2. Create a subsession using the default positioning moduleUser::LeaveIfError(positioner.Open(server));CleanupClosePushL(positioner);// 3. Set update optionsTPositionUpdateOptions puo;// Update the position every 30 secpuo.SetUpdateInterval(30000000);// Set update request timeout to 15 secondspuo.SetUpdateTimeOut(15000000);// Set the optionspositioner.SetUpdateOptions(puo);// 4. Request location information// Could also call positioner.GetLastKnownPosition(posInfo, status)// to get cached location information// Set position requestor_LIT(KRequestor,"Location Sample Application");TInt err =positionerEx.SetRequestor( CRequestor::ERequestorService,CRequestor::EFormatApplication, KRequestor );TPositionInfo posInfo;TRequestStatus status;positioner.NotifyPositionUpdate(posInfo, status);LOCATION-BASED SERVICES313// Wait on an event (in production code, you should// use an active object)User::WaitForRequest(status);// 5.
Receive location informationif (status.Int() != KErrNone){// Handle possible client-server errorsCleanupStack::PopAndDestroy(2, &server); // positioner, serverreturn status.Int();}// Get the position data object from the wrapper info objectposInfo.GetPosition(aPos);// Later on, use the obtained position information, e.g. calling// aPos.Latitude() etc. methods// 6. Close the subsession and sessionCleanupStack::PopAndDestroy(2, &server);}Various LBS classes hold position information as 32- and 64-bit realnumbers for most of the cases unless stated otherwise.
The standardmeasurement units are as follows:• Latitude and longitude are held in 64-bit real numbers. Altitude isheld in a 32-bit real number. By default, the WGS-84 datum is usedto reference coordinates. All positions returned by the location serveruse this coordinate reference system. Latitude values are in the range[−90, +90] (−90 <= latitude <= +90), whereas longitude values arein the range [−180, +180) (−180 <= longitude < +180).• Both horizontal and vertical accuracy are held in 32-bit real numbersthat represent the error offset in meters.
In practice, the actual positionlies within the respective accuracy circle with 68 % probability.• Bearings and headings are held in 32-bit real numbers and representthe direction in degrees from the true north. Their correspondingaccuracies are also held in 32-bit real numbers and represented indegrees.If you need to convert those values to the regular string representation,for instance, in the ±DDD MM?SS.SSS form, the following long (butsimple) function gives you some idea of how to do it:void GetDegreesString(const TReal64& aDegrees,TBuf<16>& aDegreesString){const TReal KSecondsInMinute = 60.0;const TInt KNumWidth = 3;314SYMBIAN C++ RECIPES// Degrees sign delimeter used in formatting methods_LIT(KDelimDegree,"\xb0"); // "◦ " symbol// Dot delimeter used in formatting methods_LIT(KDelimDot,"\x2e"); // "." symbol// Plus sign delimeter used in formatting methods_LIT(KDelimPlus,"\x2b"); // "+" symbol// Minus sign delimeter used in formatting methods_LIT(KDelimMinus,"\x2d"); // "-" symbol// Quotation sign delimeter used in formatting methods_LIT(KDelimQuot,"\x22"); // "" symbol// Apostrophe sign delimeter used in formatting methods_LIT(KApostrophe,"\x27"); // "'" symbol// Not-a-number string_LIT(KNan,"NaN");TReal64 realTmp = 0;// Check if aDegree is a proper number and exit otherwiseif ( Math::IsNaN(aDegrees) ){aDegreesString = KNan;return;}// Integer part of the degreesTInt intDegrees = 0;if ( Math::Int(realTmp,aDegrees) == KErrNone ){intDegrees = (TInt)realTmp;}// Positive float of the degreesTReal64 realDegrees = aDegrees;// Convert to positive valuesif ( intDegrees < 0 ){intDegrees = -intDegrees;realDegrees = -realDegrees;}// MinutesTReal64 realMinutes = 0;if ( Math::Frac(realMinutes,realDegrees) == KErrNone ){realMinutes *= KSecondsInMinute;}else{realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;}// Integer part of the minutesTInt intMinutes = 0;if ( Math::Int(realTmp,realMinutes) == KErrNone ){intMinutes = (TInt)realTmp;}// SecondsTReal64 realSeconds = 0;if ( Math::Frac(realSeconds,realMinutes) == KErrNone ){realSeconds *= KSecondsInMinute;LOCATION-BASED SERVICES}else{realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;}TInt intSeconds = 0;if ( Math::Int(realTmp,realSeconds) == KErrNone ){intSeconds = (TInt)realTmp;}// Check the sign of the resultif ( aDegrees >= 0 ){aDegreesString.Append(KDelimPlus);}else{aDegreesString.Append(KDelimMinus);}// Add the degreesTInt64 value = intDegrees;aDegreesString.AppendNum(value);// Add the separatoraDegreesString.Append(KDelimDegree);// Add the minutesvalue = intMinutes;aDegreesString.AppendNum(value);// Add the separatoraDegreesString.Append(KApostrophe);// Add the secondsvalue = intSeconds;aDegreesString.AppendNum(value);// Add the separatoraDegreesString.Append(KDelimQuot);// Add the separatoraDegreesString.Append(KDelimDot);// Get six last digitsrealSeconds -= intSeconds;realSeconds *= 1000;// Add the secondsaDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds),EDecimal, KNumWidth);}4.10.2.2Request Extended Location InformationAmount of time required: 30 minutesLocation of example code: \LocationRequired library(s): lbs.lib (S60), lbsselflocate.lib(UIQ)315316SYMBIAN C++ RECIPESRequired header file(s): lbs.hRequired platform security capability(s): LocationProblem: You want to obtain extended location information.Solution: In addition to the general position classes, there are two otherposition classes: TPositionCourseInfo and TPositionSatelliteInfo.
The latter class inherits from the former.TPositionCourseInfo incorporates a TCourse object, which provides information about the current speed at which the device is moving,the device’s direction in terms of bearing, and also the accuracy of theseparameters.In turn, TPositionSatelliteInfo contains information about thesatellites used in locating: how many satellites are available, which ofthose were used to produce the current estimate, and a list of the satelliteswith their data. The TSatelliteData class represents a satellite.A client gets the information by sending the appropriate TPositionInfo object to the location server via NotifyPositionUpdate().If the currently used positioning module supports the requested data,it fills the object with the data and returns it to the client.