Retriving latitude & longitiude.
i followed the below example link
[url]http://www.developer.nokia.com/Community/Wiki/Retrieving_location_information_using_Symbian_C%2B%2B[/url] to retrieve the latitude & longitude of the cell.
as per the example i implemented the MPositionObserver ABCclass to CUnregisterview class. The functions
virtual void PositionUpdatedL(TPositionInfoBase& aPosInfo) = 0;
virtual TInt ErrorL(TInt aError) = 0;
was overridden in CUnregisterview class as : -
void CUnRegisterView ::PositionUpdatedL(TPositionInfoBase& aPosInfo)
{
if (aPosInfo.PositionClassType() & EPositionInfoClass)
{
// Cast the TPositionInfoBase object to TPositionInfo
TPositionInfo* posInfo = static_cast<TPositionInfo*>(&aPosInfo);
// Get position
TPosition position;
posInfo->GetPosition(position);
// Convert positions to the descriptors
TBuf<KDegreeLength> latitudeDegr;
GetDegreesString(position.Latitude(), latitudeDegr);
// Convert positions to the descriptors
TBuf<KDegreeLength> longitudeDegr;
GetDegreesString(position.Longitude(), longitudeDegr);
}
}
GetDegreesString was defined as:----
void CUnRegisterView::GetDegreesString(
const TReal64& aDegrees,TBuf<KDegreeLength>& aDegreesString) const
{
const TReal KSecondsInMinute = 60.0;
const TInt KNumWidth = 3;
// If the aDegree is a proper number
if ( !Math::IsNaN(aDegrees) )
{
// Integer part of the degrees
TInt intDegrees = static_cast<TInt>(aDegrees);
// Positive float of the degrees
TReal64 realDegrees = aDegrees;
// Convert to positive values
if ( intDegrees < 0 )
{
intDegrees = -intDegrees;
realDegrees = -realDegrees;
}
// Minutes
TReal64 realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;
// Integer part of the minutes
TInt intMinutes = static_cast<TInt>(realMinutes);
// Seconds
TReal64 realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;
TInt intSeconds = static_cast<TInt>((realMinutes - intMinutes) * KSecondsInMinute);
// Check the sign of the result
if ( aDegrees >= 0 )
{
aDegreesString.Append(KDelimPlus);
}
else
{
aDegreesString.Append(KDelimMinus);
}
// Add the degrees
TInt64 value = intDegrees;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimDegree);
// Add the minutes
value = intMinutes;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KApostrophe);
// Add the seconds
value = intSeconds;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimQuot);
// Add the separator
aDegreesString.Append(KDelimDot);
// Get six last digits
realSeconds -= intSeconds;
realSeconds *= 1000;
// Add the seconds
aDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds),
EDecimal, KNumWidth);
}
}
IN side handle command in unregisterview under switch case i called ...
case ELocation:
{
iSearchLocation = CLocation::NewL(1000000*10,*this); //This is the pointer of CLocation* iSearchLocation;
TPositionInfoBase* pos = iSearchLocation->CurrentPosition();
PositionUpdatedL(*pos);
}
break;
PositionUpdatedL(*pos); is defined in upper section.
I am getting error of ekern exe3 in the line
TPositionInfoBase* pos = iSearchLocation->CurrentPosition();
Please help..
Thanks in advance.
Re: Retriving latitude & longitiude.
instead of defining
[B]virtual void PositionUpdatedL(TPositionInfoBase& aPosInfo) = 0;
virtual TInt ErrorL(TInt aError) = 0;[B]
define:
void PositionUpdatedL(TPositionInfoBase& aPosInfo);
TInt ErrorL(TInt aError);
Retriving the latitude & Longitude
Dear All,
I was trying the link [url]http://www.developer.nokia.com/Community/Wiki/Retrieving_location_information_using_Symbian_C%2B%2B#See_also[/url] to retrieve the Location information.
Ok,
As per this i put the .cpp & .h file in that. After that i have a interface class ...
CGpsLocationEngine;
lass CGpsLocationEngine : public CBase, public MPositionObserver
{
public:
static CGpsLocationEngine* NewL();
CGpsLocationEngine();
void ConstructL();
virtual ~CGpsLocationEngine();
void PositionUpdatedL(TPositionInfoBase& aPosInfo);
void ErrorL(TInt aError);
TPositionInfoBase* GetPositionInfoBase();
void GetDegreesString( const TReal64& aDegrees,TBuf<19>& aDegreesString) const;
void ProcessPositionInfoL(const TPositionInfo& aPositionInfo );
TDesC& LAT_LONG_String();
void GetPosition();
private: //methods
CLocation* iLocation;
};
After that in .cpp file i did the overriding of the function:-
void PositionUpdatedL(TPositionInfoBase& aPosInfo);
void ErrorL(TInt aError);
in the manner that:->
void CGpsLocationEngine::PositionUpdatedL(TPositionInfoBase& pos)
{
if (pos.PositionClassType() & EPositionInfoClass)
{
// Cast the TPositionInfoBase object to TPositionInfo
TPositionInfo* posinfo = static_cast<TPositionInfo*>(&pos);
// Process the position information
ProcessPositionInfoL( *posinfo );
}
}
void CGpsLocationEngine::ProcessPositionInfoL(
const TPositionInfo& aPositionInfo )
{
// Get basic position data
TPosition position;
aPositionInfo.GetPosition(position);
TBuf<KDegreeLength> latitudeDegr;
GetDegreesString(position.Latitude(), latitudeDegr);
TBuf<KDegreeLength> longitudeDegr;
GetDegreesString(position.Longitude(), longitudeDegr);
}
void CGpsLocationEngine::GetDegreesString(
const TReal64& aDegrees,TBuf<19>& aDegreesString) const
{
const TReal KSecondsInMinute = 60.0;
const TInt KNumWidth = 3;
// If the aDegree is a proper number
if ( !Math::IsNaN(aDegrees) )
{
// Integer part of the degrees
TInt intDegrees = static_cast<TInt>(aDegrees);
// Positive float of the degrees
TReal64 realDegrees = aDegrees;
// Convert to positive values
if ( intDegrees < 0 )
{
intDegrees = -intDegrees;
realDegrees = -realDegrees;
}
// Minutes
TReal64 realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;
// Integer part of the minutes
TInt intMinutes = static_cast<TInt>(realMinutes);
// Seconds
TReal64 realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;
TInt intSeconds = static_cast<TInt>((realMinutes - intMinutes) * KSecondsInMinute);
// Check the sign of the result
if ( aDegrees >= 0 )
{
aDegreesString.Append(KDelimPlus);
}
else
{
aDegreesString.Append(KDelimMinus);
}
// Add the degrees
TInt64 value = intDegrees;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimDegree);
// Add the minutes
value = intMinutes;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KApostrophe);
// Add the seconds
value = intSeconds;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimQuot);
// Add the separator
aDegreesString.Append(KDelimDot);
// Get six last digits
realSeconds -= intSeconds;
realSeconds *= 1000;
// Add the seconds
aDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds),
EDecimal, KNumWidth);
}
}
I am unable to understand that i have to call
// Class that use CLocation have to implement
// MPositionObserver interface. Via MPositionObserver are position
// and error messages send.
iSearchLocation = CLocation::NewL(1000000*10,*this); //It will be in ConstructL
// Get current position
TPositionInfoBase* pos = iSearchLocation->CurrentPosition();
Now suppose from a screen from a command Location i just want to retrieve the location.
In that Case i will call the function
TPositionInfoBase* pos = iSearchLocation->CurrentPosition();
"or"
PositionUpdatedL(TPositionInfoBase& pos)
How could i implement the same.
[B]Please Guide if I am wrong at any points. [/B]
Re: Retriving the latitude & Longitude
best idea would be to have callback implemented in ProcessPositionInfoL() which would tell you when it has position updated.
Re: Retriving latitude & longitiude.
[QUOTE=symbianyucca;906085]instead of defining
[B]virtual void PositionUpdatedL(TPositionInfoBase& aPosInfo) = 0;
virtual TInt ErrorL(TInt aError) = 0;[B]
define:
void PositionUpdatedL(TPositionInfoBase& aPosInfo);
TInt ErrorL(TInt aError);[/QUOTE]
Yes I did the same in the interface class.
Re: Retriving latitude & longitiude.
[QUOTE=akki123;908021]Yes I did the same in the interface class.[/QUOTE]
And what was the difference ?
Re: Retriving latitude & longitiude.
Here i am able to build & debug it for emulator. But when i am debugging it for GCCE compiler it is giving an error
undefined reference to `vtable for CGpsLocationEngine'
Re: Retriving latitude & longitiude.
The interface ("class MPositionObserver{...}") has to remain the abstract virtual thing.
When you inherit the methods in your own class, the abstract (=0) has to be removed. virtual does not matter, there is a C++ saying for this: "Once virtual, always virtual", so this property is inherited automatically.
Note that Wiki articles are created by random people, so it is always a good idea to check official examples too, given that they exist. In this case they do, the SDK-s have Location/PositionXY examples, and there are a couple here in the Code Examples section, [url]https://www.developer.nokia.com/Develop/Featured_Technologies/Symbian_C++/Code_examples/Location.xhtml[/url]