/** * Creates a position information from the passed position * @param aJniEnv A reference to the JNI environment * @param aCoordinates Latitude and longitude values * @param aCoordinateInfo Altitude, horizontal accuracy and vertical accurazy */ void CreateCoordinateInfos(JNIEnv& aJniEnv, const TLocality& aPosition, jdoubleArray aCoordinates, jfloatArray aCoordinateInfo) { JELOG2(EJavaLocation); __ASSERT_DEBUG( (aJniEnv.GetArrayLength(aCoordinates) >= KLAPINumCoordinates), LAPIError::Panic(ELAPIPanicJniIncorrectArrayLength)); __ASSERT_DEBUG((aJniEnv.GetArrayLength(aCoordinateInfo) >= KLAPINumCoordinateInfos), LAPIError::Panic( ELAPIPanicJniIncorrectArrayLength)); jdouble coordinates[KLAPINumCoordinates] = { aPosition.Latitude(), aPosition.Longitude() }; jfloat coordinateInfo[KLAPINumCoordinateInfos] = { aPosition.Altitude(), aPosition.HorizontalAccuracy(), aPosition.VerticalAccuracy() }; // Set coordinate values to the java array aJniEnv.SetDoubleArrayRegion(aCoordinates, 0, KLAPINumCoordinates, coordinates); // Set coordinate information to the java array aJniEnv.SetFloatArrayRegion(aCoordinateInfo, 0, KLAPINumCoordinateInfos, coordinateInfo); }
// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // void PosLmLandmarkHandler::SetPositionL( RDbView& aView, const CPosLandmark& aLandmark) { TLocality position; if (aLandmark.GetPosition(position) == KErrNone) { aView.SetColL(EPosLmLcLatitudeCol, position.Latitude()); aView.SetColL(EPosLmLcLongitudeCol, position.Longitude()); if (!Math::IsNaN(position.Altitude())) { aView.SetColL(EPosLmLcAltitudeCol, position.Altitude()); } else { aView.SetColNullL(EPosLmLcAltitudeCol); } if (!Math::IsNaN(position.HorizontalAccuracy())) { aView.SetColL(EPosLmLcHorizAccCol, position.HorizontalAccuracy()); } else { aView.SetColNullL(EPosLmLcHorizAccCol); } if (!Math::IsNaN(position.VerticalAccuracy())) { aView.SetColL(EPosLmLcVertAccCol, position.VerticalAccuracy()); } else { aView.SetColNullL(EPosLmLcVertAccCol); } } else { aView.SetColNullL(EPosLmLcLatitudeCol); aView.SetColNullL(EPosLmLcLongitudeCol); aView.SetColNullL(EPosLmLcAltitudeCol); aView.SetColNullL(EPosLmLcHorizAccCol); aView.SetColNullL(EPosLmLcVertAccCol); } }
// ----------------------------------------------------------------------------- // CLandmarksEditDialog::ConfigureLocationFieldsL // // (other items were commented in a header). // ----------------------------------------------------------------------------- // void CLandmarksEditDialog::ConfigureLocationFieldsL(TLocality& aLocation) { TBuf<KPosLmMaxTextFieldLength> textFieldValue; // Configure latitude in float format LandmarksUtils::LatLongToDes(aLocation.Latitude(), textFieldValue); ConfigureTextFieldL(ELandmarkLatitudeField, textFieldValue); // Configure longitude in float format LandmarksUtils::LatLongToDes(aLocation.Longitude(), textFieldValue); ConfigureTextFieldL(ELandmarkLongitudeField, textFieldValue); // Configure altitude LandmarksUtils::FloatToDesL(aLocation.Altitude(), textFieldValue, iRealFormat); ConfigureTextFieldL(ELandmarkAltitudeField, textFieldValue); // Configure horizontal accuracy LandmarksUtils::FloatToDesL(aLocation.HorizontalAccuracy(), textFieldValue, iRealFormat); ConfigureTextFieldL(ELandmarkHorAccField, textFieldValue); // Configure vertical accuracy LandmarksUtils::FloatToDesL(aLocation.VerticalAccuracy(), textFieldValue, iRealFormat); ConfigureTextFieldL(ELandmarkVerAccField, textFieldValue); }
// --------------------------------------------------------- // CPosTp148::PrintLandmarkFieldsWithDescriptionL // // (other items were commented in a header). // --------------------------------------------------------- // void CPosTp148::PrintLandmarkFieldsWithDescriptionL(const CPosLandmark& aLandmark, TBool aTraceFlag) { iLog->Log(_L("Parsing Description ... \n")); TPositionFieldId sourceFieldId = aLandmark.FirstPositionFieldId(); TLocality loc; TInt err; TPtrC landmarkName; TPtrC landmarkDescription; err = aLandmark.GetLandmarkName( landmarkName ); if ( err == KErrNone ) { HBufC* buffer = HBufC::NewLC( landmarkName.Length() + 256 ); TPtr buf = buffer->Des(); buf.Append( _L(" \tLandmark Name: ")); buf.Append( landmarkName ); iLog->Log( buf ); if( aTraceFlag ) { TraceL( buf ); } CleanupStack::PopAndDestroy( buffer ); buffer = NULL; } err = aLandmark.GetPosition(loc); if (err == KErrNone) { HBufC* buffer = HBufC::NewLC( 1024 ); TPtr buf = buffer->Des(); TRealFormat format( 12, KRealFormatFixed ); format.iPoint = TChar('.'); format.iTriLen = KDoNotUseTriads; format.iPlaces = 6; TBuf<20> sLon, sLat, sVacc, sHacc, sAlt, sRad; sLon.Num( loc.Longitude(), format ); sLat.Num( loc.Latitude(), format ); sAlt.Num( loc.Altitude(), format ); sVacc.Num( loc.VerticalAccuracy(), format ); sHacc.Num( loc.HorizontalAccuracy(), format ); buf.Format( _L("\tLM: Long %S Lat %S vertAcc %S horAcc %S alt %S "), &sLon, &sLat, &sVacc, &sHacc, &sAlt); TReal32 sourceR; err = aLandmark.GetCoverageRadius(sourceR); if (err == KErrNone ) { sRad.Num( sourceR, format ); buf.AppendFormat(_L(" srcRadius %S" ), &sRad); } iLog->Log(buf); if (aTraceFlag) TraceL(buf); CleanupStack::PopAndDestroy( buffer ); buffer = NULL; } //Get landmark description err = aLandmark.GetLandmarkDescription(landmarkDescription); if (err == KErrNone) { HBufC* buffer = HBufC::NewLC( landmarkDescription.Length() + 256 ); TPtr buf = buffer->Des(); buf.Format(_L("\tLandmark Description: ")); buf.Append(landmarkDescription); iLog->Log(buf); if ( aTraceFlag ) { TraceL( buf ); } CleanupStack::PopAndDestroy( buffer ); buffer = NULL; } while (sourceFieldId != EPositionFieldNone) { TPtrC sourceValue; aLandmark.GetPositionField(sourceFieldId, sourceValue); HBufC* buffer = HBufC::NewLC( sourceValue.Length() + 256 ); TPtr buf = buffer->Des(); buf.Format( _L( "\tIdField Id: %d Value:" ), sourceFieldId ); buf.Append( sourceValue ); iLog->Log( buf ); if ( aTraceFlag ) { TraceL( buf ); } sourceFieldId = aLandmark.NextPositionFieldId( sourceFieldId ); CleanupStack::PopAndDestroy( buffer ); } }
// ----------------------------------------------------------------------------- // CLandmarksEditDialog::SaveFormDataL // // (other items were commented in a header). // ----------------------------------------------------------------------------- // TBool CLandmarksEditDialog::SaveFormDataL() { CEikEdwin* editor = NULL; // Fetch name TBuf<KPosLmMaxTextFieldLength> name; editor = static_cast <CEikEdwin*> (Control(ELandmarkNameField)); editor->GetText(name); // Fetch description HBufC* descBuf = HBufC::NewLC(KPosLmMaxDescriptionLength); TPtr desc = descBuf->Des(); editor = static_cast <CEikEdwin*> (Control(ELandmarkDescField)); editor->GetText(desc); // Fetch existing location TLocality existingLocation; TBool locationExists = (iLandmark->GetPosition(existingLocation) == KErrNone); TRealX floatFieldValue; // Fetch Latitude TReal latitude = existingLocation.Latitude(); if (iIsRealValueEdited[ELatitudeEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkLatitudeField, R_LMREFAPP_LATITUDE_ERROR); floatFieldValue.GetTReal(latitude); } // Fetch Longitude TReal longitude = existingLocation.Longitude(); if (iIsRealValueEdited[ELongitudeEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkLongitudeField, R_LMREFAPP_LONGITUDE_ERROR); floatFieldValue.GetTReal(longitude); } // Fetch Altitude TReal32 altitude = existingLocation.Altitude(); if (iIsRealValueEdited[EAltitudeEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkAltitudeField, R_LMREFAPP_ALTITUDE_ERROR); floatFieldValue.GetTReal(altitude); } // Fetch horizontal accuracy TReal32 horAcc = existingLocation.HorizontalAccuracy(); if (iIsRealValueEdited[EHorizontalAccEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkHorAccField, R_LMREFAPP_HOR_ACC_ERROR); floatFieldValue.GetTReal(horAcc); } // Fetch vertical accuracy TReal32 verAcc = existingLocation.VerticalAccuracy(); if (iIsRealValueEdited[EVerticalAccEditor] || !locationExists) { FetchFloatL(floatFieldValue, ELandmarkVerAccField, R_LMREFAPP_VER_ACC_ERROR); floatFieldValue.GetTReal(verAcc); } // Fetch Coverage Radius TReal32 radius; TInt radiusExists = (iLandmark->GetCoverageRadius(radius) == KErrNone); if (iIsRealValueEdited[ERadiusEditor] || !radiusExists) { FetchFloatL(floatFieldValue, ELandmarkRadiusField, R_LMREFAPP_RADIUS_ERROR); floatFieldValue.GetTReal(radius); } // Fetch street TBuf<KPosLmMaxTextFieldLength> street; editor = static_cast <CEikEdwin*> (Control(ELandmarkStreetField)); editor->GetText(street); // Fetch postal code TBuf<KPosLmMaxTextFieldLength> postalCode; editor = static_cast <CEikEdwin*> (Control(ELandmarkPostalField)); editor->GetText(postalCode); // Fetch city TBuf<KPosLmMaxTextFieldLength> city; editor = static_cast <CEikEdwin*> (Control(ELandmarkCityField)); editor->GetText(city); // Fetch country TBuf<KPosLmMaxTextFieldLength> country; editor = static_cast <CEikEdwin*> (Control(ELandmarkCountryField)); editor->GetText(country); // Update category iLandmark->RemoveLandmarkAttributes(CPosLandmark::ECategoryInfo); for (TInt i = 0; i < iCategoryIds.Count(); i++) { iLandmark->AddCategoryL(iCategoryIds[i]); } // Check that at least some data is entered if (!name.Length() && !desc.Length() && !street.Length() && !city.Length() && !country.Length() && !postalCode.Length() && !iCategoryIds.Count() && Math::IsNaN(latitude) && Math::IsNaN(longitude) && Math::IsNaN(altitude) && Math::IsNaN(radius) && Math::IsNaN(horAcc) && Math::IsNaN(verAcc)) { NotifyErrorToUserL(R_LMREFAPP_EMPTY_LANDMARK); } // Update name iLandmark->SetLandmarkNameL(name); // Update description iLandmark->SetLandmarkDescriptionL(desc); CleanupStack::PopAndDestroy(descBuf); // Update coverage radius if (!Math::IsNaN(radius) && radius < 0) { NotifyErrorToUserL(R_LMREFAPP_RADIUS_ERROR); } iLandmark->SetCoverageRadius(radius); // Update street iLandmark->SetPositionFieldL(EPositionFieldStreet, street); // Update postal code iLandmark->SetPositionFieldL(EPositionFieldPostalCode, postalCode); // Update city iLandmark->SetPositionFieldL(EPositionFieldCity, city); // Update country iLandmark->SetPositionFieldL(EPositionFieldCountry, country); // Update location. There are some rules specified by TLocality and // TCoordinate how to update a location. These rules are taken into // account below when validating the location data. if (Math::IsNaN(latitude) && Math::IsNaN(longitude)) { // If lat long are undefined, then alt and hAcc // must be undefined if (!Math::IsNaN(horAcc)) { NotifyErrorToUserL(R_LMREFAPP_HACC_LAT_LONG_ERROR); } else if (!Math::IsNaN(altitude)) { NotifyErrorToUserL(R_LMREFAPP_ALT_LAT_LONG_ERROR); } else if (!Math::IsNaN(verAcc)) { NotifyErrorToUserL(R_LMREFAPP_VACC_ALT_ERROR); } else { // None position fields are set, Remove position info. iLandmark->RemoveLandmarkAttributes(CPosLandmark::EPosition); } } else if (!Math::IsNaN(latitude) && !Math::IsNaN(longitude)) { // If lat long are defined, hAcc must be positive if defined if (!Math::IsNaN(horAcc) && horAcc < 0) { NotifyErrorToUserL(R_LMREFAPP_HOR_ACC_ERROR); } // if altitude is undefined, then vertical accuracy // must be undefined if (Math::IsNaN(altitude) && !Math::IsNaN(verAcc)) { NotifyErrorToUserL(R_LMREFAPP_VACC_ALT_ERROR); } // vertical accuracy must be positive if defined if (!Math::IsNaN(verAcc) && verAcc < 0) { NotifyErrorToUserL(R_LMREFAPP_VER_ACC_ERROR); } // We are allowed to set the new locality TCoordinate coordinate(latitude, longitude, altitude); TLocality newLocation(coordinate, horAcc, verAcc); iLandmark->SetPositionL(newLocation); } else { // Inform user that no valid lat/long has been entered NotifyErrorToUserL(R_LMREFAPP_LAT_LONG_ERROR); } iEdited = ETrue; return ETrue; }