locationmanager/locationtrail/src/clocationrecord.cpp
changeset 45 a93990e5815e
parent 36 aa5a574040a4
child 52 40db28bb26b8
equal deleted inserted replaced
36:aa5a574040a4 45:a93990e5815e
    19 #include <lbserrors.h>
    19 #include <lbserrors.h>
    20 #include <lbssatellite.h>
    20 #include <lbssatellite.h>
    21 #include <ecom.h>
    21 #include <ecom.h>
    22 #include <centralrepository.h>
    22 #include <centralrepository.h>
    23 #include <hwrmpowerstatesdkpskeys.h>
    23 #include <hwrmpowerstatesdkpskeys.h>
       
    24 #ifdef LOC_GEOTAGGING_CELLID
       
    25 #include <lbslocationinfo.h>
       
    26 #endif //LOC_GEOTAGGING_CELLID
    24 
    27 
    25 #include "rlocationtrail.h"
    28 #include "rlocationtrail.h"
    26 #include "clocationrecord.h"
    29 #include "clocationrecord.h"
    27 #include "cnetworkinfo.h"
    30 #include "cnetworkinfo.h"
    28 #include "locationmanagerdebug.h"
    31 #include "locationmanagerdebug.h"
    99 #ifdef LOC_REVERSEGEOCODE
   102 #ifdef LOC_REVERSEGEOCODE
   100     ,iConnectionOption(ESilent)
   103     ,iConnectionOption(ESilent)
   101 	,iImageQuery(NULL)
   104 	,iImageQuery(NULL)
   102 	,iTagQuery(NULL)
   105 	,iTagQuery(NULL)
   103     ,iTagCreator( NULL )
   106     ,iTagCreator( NULL )
       
   107     ,iLastReverseGeocodeFails(EFalse)
   104 	,iRevGeocoderPlugin( NULL )
   108 	,iRevGeocoderPlugin( NULL )
   105 #endif
   109 #endif
   106     {
   110     {
   107     iMaxTrailSize = KMaxTrailLength / KUpdateInterval;
   111     iMaxTrailSize = KMaxTrailLength / KUpdateInterval;
   108     }
   112     }
   130     iNetworkInfoTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   134     iNetworkInfoTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   131 
   135 
   132 #ifdef LOC_REVERSEGEOCODE
   136 #ifdef LOC_REVERSEGEOCODE
   133     iTagCreator = CTagCreator::NewL();
   137     iTagCreator = CTagCreator::NewL();
   134 
   138 
   135 
   139     iRevGeocoderPlugin = reinterpret_cast<CReverseGeoCoderPlugin*>(
   136     if (!iRevGeocoderPlugin)
   140           REComSession::CreateImplementationL(KReverseGeoCodeUid,iDtorKey));
   137         {
   141 
   138         iRevGeocoderPlugin = reinterpret_cast<CReverseGeoCoderPlugin*>(
   142      iRevGeocoderPlugin->AddObserverL(*this);
   139               REComSession::CreateImplementationL(KReverseGeoCodeUid,iDtorKey));
   143 
   140         if(iRevGeocoderPlugin)
   144 
   141             {
       
   142             iRevGeocoderPlugin->AddObserverL(*this);
       
   143             }
       
   144          }
       
   145  
   145  
   146  #endif
   146  #endif
   147 
   147 
   148 	
   148 	
   149     TInt interval( 0 );
   149     TInt interval( 0 );
   199 #ifdef LOC_REVERSEGEOCODE
   199 #ifdef LOC_REVERSEGEOCODE
   200     iLocationItems.ResetAndDestroy();
   200     iLocationItems.ResetAndDestroy();
   201     iLocationItems.Close();
   201     iLocationItems.Close();
   202 #endif    
   202 #endif    
   203     delete iNetworkInfoChangeListener;
   203     delete iNetworkInfoChangeListener;
       
   204     iNetworkInfoChangeListener = NULL;
   204     delete iPositionInfo;
   205     delete iPositionInfo;
       
   206     iPositionInfo = NULL;
   205     delete iNetworkInfoTimer;
   207     delete iNetworkInfoTimer;
       
   208     iNetworkInfoTimer = NULL;
   206 #ifdef LOC_GEOTAGGING_CELLID
   209 #ifdef LOC_GEOTAGGING_CELLID
   207     if(iGeoConverter)
   210     if(iGeoConverter)
   208         {
   211         {
   209         delete iGeoConverter;
   212         delete iGeoConverter;
   210         iGeoConverter = NULL;
   213         iGeoConverter = NULL;
   353     _LIT( KDateTimeFormat, "%Y/%M/%D %H:%T:%S" );
   356     _LIT( KDateTimeFormat, "%Y/%M/%D %H:%T:%S" );
   354     const TInt DateTimeStrMaxLength = 20;
   357     const TInt DateTimeStrMaxLength = 20;
   355     LOG1( "CLocationRecord::GetLocationByTimeL - aTime: %Ld", aTime.Int64() );
   358     LOG1( "CLocationRecord::GetLocationByTimeL - aTime: %Ld", aTime.Int64() );
   356     TBuf<DateTimeStrMaxLength> str1;
   359     TBuf<DateTimeStrMaxLength> str1;
   357     aTime.FormatL( str1, KDateTimeFormat );
   360     aTime.FormatL( str1, KDateTimeFormat );
   358    // LOG1( "CLocationRecord::GetLocationByTimeL - aTime: %S", &str1 );
   361     LOG1( "CLocationRecord::GetLocationByTimeL - aTime: %S", &str1 );
   359 #endif
   362 #endif
   360 
   363 
   361     TTimeIntervalSeconds interval;
   364     TTimeIntervalSeconds interval;
   362     TTimeIntervalSeconds nextInterval;
   365     TTimeIntervalSeconds nextInterval;
   363     for ( TInt i(iTrail.Count()-1) ; i >= 0 && !posFound ; i-- )
   366     for ( TInt i(iTrail.Count()-1) ; i >= 0 && !posFound ; i-- )
   368 
   371 
   369 #ifdef _DEBUG
   372 #ifdef _DEBUG
   370         LOG1( "CLocationRecord::GetLocationByTimeL - Trail timestamp: %Ld", iTrail[i]->iTimeStamp.Int64() );
   373         LOG1( "CLocationRecord::GetLocationByTimeL - Trail timestamp: %Ld", iTrail[i]->iTimeStamp.Int64() );
   371         TBuf<DateTimeStrMaxLength> str;
   374         TBuf<DateTimeStrMaxLength> str;
   372         iTrail[i]->iTimeStamp.FormatL( str, KDateTimeFormat );
   375         iTrail[i]->iTimeStamp.FormatL( str, KDateTimeFormat );
   373         //LOG1( "CLocationRecord::GetLocationByTimeL - Trail timestamp: %S", &str );
   376         LOG1( "CLocationRecord::GetLocationByTimeL - Trail timestamp: %S", &str );
   374         LOG1( "CLocationRecord::GetLocationByTimeL - timeDiff: %d", timeDiff );
   377         LOG1( "CLocationRecord::GetLocationByTimeL - timeDiff: %d", timeDiff );
   375 #endif
   378 #endif
   376 
   379 
   377         if ( err == KErrNone && timeDiff <= KMaximumIntervalSeconds )
   380         if ( err == KErrNone && timeDiff <= KMaximumIntervalSeconds )
   378             {
   381             {
   705         iNetwork = aNetworkInfo;
   708         iNetwork = aNetworkInfo;
   706         if (iNetwork.iAccess == CTelephony::ENetworkAccessUtran)
   709         if (iNetwork.iAccess == CTelephony::ENetworkAccessUtran)
   707         	{
   710         	{
   708         	iNetwork.iLocationAreaCode = 0;
   711         	iNetwork.iLocationAreaCode = 0;
   709         	}
   712         	}
       
   713 #ifdef LOC_GEOTAGGING_CELLID
   710         if ( iState == RLocationTrail::ETrailStarting && iTrailStarted )
   714         if ( iState == RLocationTrail::ETrailStarting && iTrailStarted )
   711         	{
   715         	{
   712         	SetCurrentState( RLocationTrail::ETrailStarted );
   716         	SetCurrentState( RLocationTrail::ETrailStarted );
   713         	}
   717         	}
       
   718 #endif        
   714         }
   719         }
   715     else
   720     else
   716         {
   721         {
   717         LOG1("CLocationRecord::NetworkInfo - %d", aError );
   722         LOG1("CLocationRecord::NetworkInfo - %d", aError );
   718         iNetwork = CTelephony::TNetworkInfoV1();
   723         iNetwork = CTelephony::TNetworkInfoV1();
   795     LOG1( "CLocationRecord::SetCurrentState(), begin, state:%d", aState );
   800     LOG1( "CLocationRecord::SetCurrentState(), begin, state:%d", aState );
   796     iState = aState;
   801     iState = aState;
   797     if( iTrailStarted )
   802     if( iTrailStarted )
   798         {
   803         {
   799         // Set the property only when trail is started to avoid icon flickering and wrong icon update in UI
   804         // Set the property only when trail is started to avoid icon flickering and wrong icon update in UI
   800         if( iGpsDataAvailableFlag  || 
   805         if( iGpsDataAvailableFlag  
   801             iNetwork.iCellId > 0 && 
   806 #ifdef LOC_GEOTAGGING_CELLID
       
   807             || ( iNetwork.iCellId > 0 && 
   802             ((iNetwork.iLocationAreaCode == 0 && iNetwork.iAccess == CTelephony::ENetworkAccessUtran) || // 3G
   808             ((iNetwork.iLocationAreaCode == 0 && iNetwork.iAccess == CTelephony::ENetworkAccessUtran) || // 3G
   803             (iNetwork.iLocationAreaCode > 0 && (iNetwork.iAccess == CTelephony::ENetworkAccessGsm ||  // 2G
   809             (iNetwork.iLocationAreaCode > 0 && (iNetwork.iAccess == CTelephony::ENetworkAccessGsm ||  // 2G
   804             						iNetwork.iAccess == CTelephony::ENetworkAccessGsmCompact)))  &&
   810             						iNetwork.iAccess == CTelephony::ENetworkAccessGsmCompact)))  &&
   805             iNetwork.iCountryCode.Length() > 0 &&
   811             iNetwork.iCountryCode.Length() > 0 &&
   806             iNetwork.iNetworkId.Length() > 0 )
   812             iNetwork.iNetworkId.Length() > 0 )
       
   813 #endif // LOC_GEOTAGGING_CELLID            
       
   814             )
   807             {
   815             {
   808             // set the value 3 to have Geo tag available icon else not available.
   816             // set the value 3 to have Geo tag available icon else not available.
   809             iProperty.Set( KPSUidLocationTrail, KLocationTrailState, 
   817             iProperty.Set( KPSUidLocationTrail, KLocationTrailState, 
   810                 (TInt) RLocationTrail::ETrailStarted );
   818                 (TInt) RLocationTrail::ETrailStarted );
   811             }
   819             }
  1051 				lastnet->iCountryCode == net->iCountryCode &&
  1059 				lastnet->iCountryCode == net->iCountryCode &&
  1052 				lastnet->iNetworkId == net->iNetworkId )
  1060 				lastnet->iNetworkId == net->iNetworkId )
  1053 			{
  1061 			{
  1054 			
  1062 			
  1055 			// if both locations have valid coordinates, calculate distance between points
  1063 			// if both locations have valid coordinates, calculate distance between points
  1056 			if ( !Math::IsNaN( lastLocationData.iPosition.Latitude() ) && 
  1064 			if (
       
  1065 #ifdef LOC_REVERSEGEOCODE
       
  1066                 !iLastReverseGeocodeFails &&
       
  1067 #endif //LOC_REVERSEGEOCODE
       
  1068                 !Math::IsNaN( lastLocationData.iPosition.Latitude() ) && 
  1057 					!Math::IsNaN( lastLocationData.iPosition.Longitude() ) && 
  1069 					!Math::IsNaN( lastLocationData.iPosition.Longitude() ) && 
  1058 					!Math::IsNaN( locationData.iPosition.Latitude() ) && 
  1070 					!Math::IsNaN( locationData.iPosition.Latitude() ) && 
  1059 					!Math::IsNaN( locationData.iPosition.Longitude() ))
  1071 					!Math::IsNaN( locationData.iPosition.Longitude() ))
  1060 				{
  1072 				{
  1061 				TReal32 distance;
  1073 				TReal32 distance;
  1189          }
  1201          }
  1190         
  1202         
  1191      const TReal64 KMeterInDegrees = 0.000009;
  1203      const TReal64 KMeterInDegrees = 0.000009;
  1192      const TReal64 KPi = 3.14159265358979;
  1204      const TReal64 KPi = 3.14159265358979;
  1193      const TReal32 K180Degrees = 180.0;
  1205      const TReal32 K180Degrees = 180.0;
  1194      
       
  1195      //TLocationData locationData = iMediaItems[0].iLocationData;
       
  1196             
  1206             
  1197      TReal64 latitude = iMediaItems[0]->iLocationData.iPosition.Latitude();
  1207      TReal64 latitude = iMediaItems[0]->iLocationData.iPosition.Latitude();
  1198      TReal64 longitude = iMediaItems[0]->iLocationData.iPosition.Longitude();
  1208      TReal64 longitude = iMediaItems[0]->iLocationData.iPosition.Longitude();
  1199      // calculate distance in degrees
  1209      // calculate distance in degrees
  1200      TReal64 cosine;
  1210      TReal64 cosine;
  1320 	
  1330 	
  1321 	// location related properties
  1331 	// location related properties
  1322 	if ( !Math::IsNaN( aLocationData.iPosition.Latitude() ) && 
  1332 	if ( !Math::IsNaN( aLocationData.iPosition.Latitude() ) && 
  1323 		 !Math::IsNaN( aLocationData.iPosition.Longitude() ))
  1333 		 !Math::IsNaN( aLocationData.iPosition.Longitude() ))
  1324 		{
  1334 		{
       
  1335         LOG1("Lan - %f", aLocationData.iPosition.Latitude());
       
  1336         LOG1("Lon - %f", aLocationData.iPosition.Longitude());
  1325 		locationObject->AddReal64PropertyL( *iLatitudeDef, aLocationData.iPosition.Latitude() );
  1337 		locationObject->AddReal64PropertyL( *iLatitudeDef, aLocationData.iPosition.Latitude() );
  1326 		locationObject->AddReal64PropertyL( *iLongitudeDef, aLocationData.iPosition.Longitude() );
  1338 		locationObject->AddReal64PropertyL( *iLongitudeDef, aLocationData.iPosition.Longitude() );
  1327 
  1339 
  1328 		}
  1340 		}
  1329 	if ( !Math::IsNaN( aLocationData.iPosition.Altitude() ) )
  1341 	if ( !Math::IsNaN( aLocationData.iPosition.Altitude() ) )
  1342 		{
  1354 		{
  1343 		locationObject->AddReal32PropertyL( qualityDef, aLocationData.iQuality );
  1355 		locationObject->AddReal32PropertyL( qualityDef, aLocationData.iQuality );
  1344 		}
  1356 		}
  1345 
  1357 
  1346 	// network related properties
  1358 	// network related properties
  1347 	if ( aLocationData.iNetworkInfo.iAreaKnown )
  1359 	if ( aLocationData.iNetworkInfo.iAccess != CTelephony::ENetworkAccessUnknown )
  1348 		{
  1360 		{
  1349 		if ( aLocationData.iNetworkInfo.iAccess != CTelephony::ENetworkAccessUnknown )
  1361 		LOG1("Cell id - %d", aLocationData.iNetworkInfo.iCellId);
  1350 			{
  1362 		locationObject->AddUint32PropertyL( cellIdDef, aLocationData.iNetworkInfo.iCellId );
  1351 			locationObject->AddUint32PropertyL( cellIdDef, aLocationData.iNetworkInfo.iCellId );
  1363 		}
  1352 			
  1364 	if ( aLocationData.iNetworkInfo.iAreaKnown && 
  1353 			}
  1365         aLocationData.iNetworkInfo.iLocationAreaCode != 0 &&
  1354 		if ( aLocationData.iNetworkInfo.iLocationAreaCode != 0 &&
  1366 		aLocationData.iNetworkInfo.iAccess != CTelephony::ENetworkAccessUnknown )
  1355 			aLocationData.iNetworkInfo.iAccess != CTelephony::ENetworkAccessUnknown )
  1367 		{
  1356 			{
  1368 		LOG1("Areacode - %d", aLocationData.iNetworkInfo.iLocationAreaCode);
  1357 			locationObject->AddUint32PropertyL( locationCodeDef, 
  1369 		locationObject->AddUint32PropertyL( locationCodeDef, 
  1358 					aLocationData.iNetworkInfo.iLocationAreaCode );
  1370 				aLocationData.iNetworkInfo.iLocationAreaCode );
  1359 			
  1371 		}
  1360 			}
  1372 #ifdef _DEBUG
  1361 		if ( aLocationData.iNetworkInfo.iCountryCode.Length() > 0 )
  1373     TLex lexer( aLocationData.iNetworkInfo.iCountryCode );
  1362 			{
  1374     TUint countryCode = 0;
  1363 			locationObject->AddTextPropertyL( countryCodeDef, 
  1375     
  1364 					aLocationData.iNetworkInfo.iCountryCode );
  1376     User::LeaveIfError( lexer.Val( countryCode, EDecimal) );
  1365 			
  1377     LOG1("Country code - %d", countryCode);
  1366 			}
  1378     
  1367 		if ( aLocationData.iNetworkInfo.iNetworkId.Length() > 0 )
  1379     //Set mobile network code
  1368 			{
  1380     lexer = aLocationData.iNetworkInfo.iNetworkId;
  1369 			locationObject->AddTextPropertyL(networkCodeDef, aLocationData.iNetworkInfo.iNetworkId);
  1381     TUint networkCode = 0;
  1370 			
  1382     User::LeaveIfError( lexer.Val( networkCode, EDecimal) );
  1371 			}
  1383     LOG1("Network id - %d", networkCode);
       
  1384 #endif
       
  1385 	if ( aLocationData.iNetworkInfo.iCountryCode.Length() > 0 )
       
  1386 		{
       
  1387 		locationObject->AddTextPropertyL( countryCodeDef, 
       
  1388 				aLocationData.iNetworkInfo.iCountryCode );
       
  1389 		}
       
  1390 
       
  1391 	if ( aLocationData.iNetworkInfo.iNetworkId.Length() > 0 )
       
  1392 		{
       
  1393 		locationObject->AddTextPropertyL(networkCodeDef, aLocationData.iNetworkInfo.iNetworkId);
  1372 		}
  1394 		}
  1373 	        
  1395 	        
  1374 	// Add the location object to the database.
  1396 	// Add the location object to the database.
  1375 	locationObjectId = iMdeSession->AddObjectL( *locationObject );
  1397 	locationObjectId = iMdeSession->AddObjectL( *locationObject );
  1376 
  1398     LOG1("Location id - %d", locationObjectId);
  1377 	CleanupStack::PopAndDestroy( locationObject );
  1399 	CleanupStack::PopAndDestroy( locationObject );
  1378     LOG( "CLocationRecord::DoCreateLocationL(), end" );
  1400     LOG( "CLocationRecord::DoCreateLocationL(), end" );
  1379 
  1401 
  1380 	return locationObjectId;
  1402 	return locationObjectId;
  1381 	}
  1403 	}
  1551 void CLocationRecord::HandleFindLocationFromDB()
  1573 void CLocationRecord::HandleFindLocationFromDB()
  1552     {
  1574     {
  1553     LOG( "CLocationRecord::HandleFindLocationFromDB(), begin" );    
  1575     LOG( "CLocationRecord::HandleFindLocationFromDB(), begin" );    
  1554 	if ( iMediaItems.Count() > 0 )
  1576 	if ( iMediaItems.Count() > 0 )
  1555 	   {
  1577 	   {
  1556 		//TODO: by module owner
       
  1557 		TInt trapErr = KErrNone;
  1578 		TInt trapErr = KErrNone;
  1558 		TRAP(trapErr,FindLocationFromDBL());
  1579 		TRAP(trapErr,FindLocationFromDBL());
  1559 		// no memory, don't proceed further
  1580 		// no memory, don't proceed further
  1560 		// other error sceenario, we can move the node to the end and process the next
  1581 		// other error sceenario, we can move the node to the end and process the next
  1561 		if(trapErr != KErrNoMemory && trapErr != KErrNone)
  1582 		if(trapErr != KErrNoMemory && trapErr != KErrNone)
  1822             iGeoConverter->ConvertL(iMediaItems[0]->iLocationData.iNetworkInfo);
  1843             iGeoConverter->ConvertL(iMediaItems[0]->iLocationData.iNetworkInfo);
  1823             iMediaHandlingFlag |= KSnapGeoConvertInProgress;
  1844             iMediaHandlingFlag |= KSnapGeoConvertInProgress;
  1824             iMediaHandlingFlag &= ~KSnapGeoConvertInPendingState;
  1845             iMediaHandlingFlag &= ~KSnapGeoConvertInPendingState;
  1825             }
  1846             }
  1826 #else
  1847 #else
       
  1848         // cell id based geo tagging is not supported.. go for remapping.
  1827         locationId = DoCreateLocationL( iMediaItems[0]->iLocationData );
  1849         locationId = DoCreateLocationL( iMediaItems[0]->iLocationData );
  1828         iMediaItems[0]->iLocationId = locationId;
  1850         iMediaItems[0]->iLocationId = locationId;
  1829         CreateRelationL( iMediaItems[0]->iObjectId, locationId );
  1851         TItemId relationId = CreateRelationL( iMediaItems[0]->iObjectId, locationId );
  1830         TLocationSnapshotItem* firstPtr = iMediaItems[0];
  1852         TLocationSnapshotItem* firstPtr = iMediaItems[0];
       
  1853 
       
  1854         // Go for remapping.. get locationdata from trail with object time
       
  1855         TTime timestamp = GetMdeObjectTimeL( iMediaItems[0]->iObjectId );
       
  1856         TRemapItem remapItem;
       
  1857         remapItem.iObjectId = iMediaItems[0]->iObjectId;
       
  1858         remapItem.iTime = timestamp;
       
  1859         remapItem.iLocationId = locationId;
       
  1860         remapItem.iRelationId = relationId;
       
  1861         iRemapper->Append( remapItem );
       
  1862         
  1831         iMediaItems.Remove(0);
  1863         iMediaItems.Remove(0);
  1832         delete firstPtr;
  1864         delete firstPtr;
  1833         iMediaItems.Compress();
  1865         iMediaItems.Compress();
  1834         iMediaHandlingFlag &= ~KLocationQueryInProgress;
  1866         iMediaHandlingFlag &= ~KLocationQueryInProgress;
  1835         if ( iMediaItems.Count() > 0 )
  1867         if ( iMediaItems.Count() > 0 )
  1879             iNewItem.iLocationData.iPosition.SetCoordinate
  1911             iNewItem.iLocationData.iPosition.SetCoordinate
  1880                 ( aPosition.Latitude(), aPosition.Longitude(), aPosition.Altitude());
  1912                 ( aPosition.Latitude(), aPosition.Longitude(), aPosition.Altitude());
  1881             iNewItem.iLocationData.iQuality = aPosition.HorizontalAccuracy();
  1913             iNewItem.iLocationData.iQuality = aPosition.HorizontalAccuracy();
  1882             TItemId locationId = DoCreateLocationL( iNewItem.iLocationData );
  1914             TItemId locationId = DoCreateLocationL( iNewItem.iLocationData );
  1883             iRemapper->UpdateRelationsL( locationId ); 
  1915             iRemapper->UpdateRelationsL( locationId ); 
  1884             // TODO: remap.
       
  1885 #ifdef LOC_REVERSEGEOCODE
  1916 #ifdef LOC_REVERSEGEOCODE
  1886             if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress))
  1917             if(!(iMediaHandlingFlag & KReverseGeoCodingInProgress))
  1887                 {
  1918                 {
  1888                 iRemapState = ERemapRevGeoCodeInProgress;
  1919                 iRemapState = ERemapRevGeoCodeInProgress;
  1889                 //Find the address by coordinate, results a call to ReverseGeocodeComplete()
  1920                 //Find the address by coordinate, results a call to ReverseGeocodeComplete()
  1909                 ( aPosition.Latitude(), aPosition.Longitude(), aPosition.Altitude());
  1940                 ( aPosition.Latitude(), aPosition.Longitude(), aPosition.Altitude());
  1910            iMediaItems[0]->iLocationData.iQuality = aPosition.HorizontalAccuracy();
  1941            iMediaItems[0]->iLocationData.iQuality = aPosition.HorizontalAccuracy();
  1911            TLocationSnapshotItem* item = iMediaItems[0];
  1942            TLocationSnapshotItem* item = iMediaItems[0];
  1912            TItemId locationId = DoCreateLocationL( iMediaItems[0]->iLocationData );
  1943            TItemId locationId = DoCreateLocationL( iMediaItems[0]->iLocationData );
  1913            iMediaItems[0]->iLocationId = locationId;
  1944            iMediaItems[0]->iLocationId = locationId;
  1914            CreateRelationL( iMediaItems[0]->iObjectId, locationId );
  1945            TItemId relationId = CreateRelationL( iMediaItems[0]->iObjectId, locationId );
       
  1946 
       
  1947            // Go for remapping.. get locationdata from trail with object time
       
  1948            TTime timestamp = GetMdeObjectTimeL( iMediaItems[0]->iObjectId );
       
  1949            TRemapItem remapItem;
       
  1950            remapItem.iObjectId = iMediaItems[0]->iObjectId;
       
  1951            remapItem.iTime = timestamp;
       
  1952            remapItem.iLocationId = locationId;
       
  1953            remapItem.iRelationId = relationId;
       
  1954            iRemapper->Append( remapItem );
       
  1955 
  1915            if((iMediaItems[0]->iFlag & KSnapMediaFile) > 0)
  1956            if((iMediaItems[0]->iFlag & KSnapMediaFile) > 0)
  1916                {
  1957                {
  1917                iLastMediaItem = *(iMediaItems[0]);
  1958                iLastMediaItem = *(iMediaItems[0]);
  1918                }
  1959                }
  1919            iMediaItems.Remove(0);
  1960            iMediaItems.Remove(0);
  1950                 iRemapState = ERemapProgressNone;
  1991                 iRemapState = ERemapProgressNone;
  1951                 }
  1992                 }
  1952             else if ( iMediaItems.Count() > 0 )
  1993             else if ( iMediaItems.Count() > 0 )
  1953                 {
  1994                 {
  1954                 TLocationSnapshotItem* item = iMediaItems[0];
  1995                 TLocationSnapshotItem* item = iMediaItems[0];
       
  1996                 // Fails may be becuase of n/w reason..create location + relation so that we can handle at 3:00 AM.
       
  1997                 TItemId locationId = DoCreateLocationL( iMediaItems[0]->iLocationData );
       
  1998                 iMediaItems[0]->iLocationId = locationId;
       
  1999                 TItemId relationId = CreateRelationL( iMediaItems[0]->iObjectId, locationId );
       
  2000 
       
  2001                 // Go for remapping.. get locationdata from trail with object time
       
  2002                 TTime timestamp = GetMdeObjectTimeL( iMediaItems[0]->iObjectId );
       
  2003                 TRemapItem remapItem;
       
  2004                 remapItem.iObjectId = iMediaItems[0]->iObjectId;
       
  2005                 remapItem.iTime = timestamp;
       
  2006                 remapItem.iLocationId = locationId;
       
  2007                 remapItem.iRelationId = relationId;
       
  2008                 iRemapper->Append( remapItem );
       
  2009 
  1955                 iMediaItems.Remove(0);
  2010                 iMediaItems.Remove(0);
  1956                 iMediaItems.Compress();
  2011                 iMediaItems.Compress();
  1957                 iMediaHandlingFlag &= ~KLocationQueryInProgress;
  2012                 iMediaHandlingFlag &= ~KLocationQueryInProgress;
  1958                 delete item;
  2013                 delete item;
  1959                 }
  2014                 }
  2207         cond.AddPropertyConditionL( networkCodeDef, ETextPropertyConditionCompareEquals,
  2262         cond.AddPropertyConditionL( networkCodeDef, ETextPropertyConditionCompareEquals,
  2208                 iMediaItems[0]->iLocationData.iNetworkInfo.iNetworkId );
  2263                 iMediaItems[0]->iLocationData.iNetworkInfo.iNetworkId );
  2209             
  2264             
  2210         iNetLocationQuery->FindL(1, 1); 
  2265         iNetLocationQuery->FindL(1, 1); 
  2211         iMediaHandlingFlag |= KLocationQueryInProgress;
  2266         iMediaHandlingFlag |= KLocationQueryInProgress;
  2212     //    iMediaHandlingFlag |= KNetQueryInProgress;
       
  2213         }
  2267         }
  2214     else
  2268     else
  2215         {
  2269         {
  2216         TLocationSnapshotItem* firstPtr = iMediaItems[0];
  2270         TLocationSnapshotItem* firstPtr = iMediaItems[0];
  2217         iMediaItems.Remove(0);
  2271         iMediaItems.Remove(0);
  2459     TItemId countryTagId(0);
  2513     TItemId countryTagId(0);
  2460     TItemId cityTagId(0);
  2514     TItemId cityTagId(0);
  2461     
  2515     
  2462     iMediaHandlingFlag &= (~KReverseGeoCodingInProgress);
  2516     iMediaHandlingFlag &= (~KReverseGeoCodingInProgress);
  2463 	TLocationSnapshotItem* snapshotItem = NULL;
  2517 	TLocationSnapshotItem* snapshotItem = NULL;
       
  2518     LOG1("Error - %d", aErrorcode);
  2464     if( aErrorcode == KErrNone )
  2519     if( aErrorcode == KErrNone )
  2465         {
  2520         {
       
  2521         iLastReverseGeocodeFails = EFalse;
  2466         TPtrC countryPtr( aAddressInfo.GetCountryName() );
  2522         TPtrC countryPtr( aAddressInfo.GetCountryName() );
  2467         TPtrC cityPtr( aAddressInfo.GetCity() );
  2523         TPtrC cityPtr( aAddressInfo.GetCity() );
  2468         TRAP_IGNORE( iTagCreator->CreateLocationTagsL( countryPtr, countryTagId, 
  2524         TRAP_IGNORE( iTagCreator->CreateLocationTagsL( countryPtr, countryTagId, 
  2469                                                       cityPtr, cityTagId ) );
  2525                                                       cityPtr, cityTagId ) );
  2470         if ( iRemapState == ERemapRevGeoCodeInProgress)
  2526         if ( iRemapState == ERemapRevGeoCodeInProgress)
  2480                 iLocationItems[0]->iCityTagId = cityTagId;
  2536                 iLocationItems[0]->iCityTagId = cityTagId;
  2481                 iLastLocationItem = (*iLocationItems[0]);
  2537                 iLastLocationItem = (*iLocationItems[0]);
  2482                 
  2538                 
  2483                 TRAP_IGNORE( iTagCreator->AttachTagsL( 
  2539                 TRAP_IGNORE( iTagCreator->AttachTagsL( 
  2484                                 iLocationItems[0]->iObjectId, countryTagId, cityTagId  ) );
  2540                                 iLocationItems[0]->iObjectId, countryTagId, cityTagId  ) );
       
  2541                 if ( (iLastMediaItem.iFlag & KSnapMediaFile) > 0 
       
  2542                     && iLastMediaItem.iLocationId == iLastLocationItem.iLocationId )
       
  2543                     {
       
  2544                     LOG("Updating country/city\n");
       
  2545                     iLastMediaItem.iCountryTagId = countryTagId;
       
  2546                     iLastMediaItem.iCityTagId = cityTagId;
       
  2547                     }
       
  2548                 
  2485                 }
  2549                 }
  2486             }
  2550             }
  2487         if(iLastMediaItem.iFlag == 0)
       
  2488             {
       
  2489             LOG("Last media item is null\n");
       
  2490             }
       
  2491         if ( iLastMediaItem.iFlag > 0 && iLastMediaItem.iLocationId == iLastLocationItem.iLocationId )
       
  2492             {
       
  2493             LOG("Updating country/city\n");
       
  2494             iLastMediaItem.iCountryTagId = countryTagId;
       
  2495             iLastMediaItem.iCityTagId = cityTagId;
       
  2496             }
       
  2497         
       
  2498         //check other items in the array has same location 
  2551         //check other items in the array has same location 
  2499         for ( TInt index = iLocationItems.Count() - 1; index > 0; index--)
  2552         for ( TInt index = iLocationItems.Count() - 1; index > 0; index--)
  2500             {
  2553             {
  2501             if ( iLocationItems[index]->iLocationId == iLastLocationItem.iLocationId )
  2554             if ( iLocationItems[index]->iLocationId == iLastLocationItem.iLocationId )
  2502                 {
  2555                 {
  2510             }
  2563             }
  2511         }
  2564         }
  2512     else
  2565     else
  2513         {
  2566         {
  2514         //handle error
  2567         //handle error
       
  2568         LOG("Reverse geo coding fails");
       
  2569         iLastReverseGeocodeFails = ETrue;
  2515         }
  2570         }
  2516     
  2571     
  2517     //irrespective of error or not, remove current(first) item to proceed further
  2572     //irrespective of error or not, remove current(first) item to proceed further
  2518     if ( iLocationItems.Count() > 0 )
  2573     if ( iLocationItems.Count() > 0 )
  2519         {
  2574         {