locationdataharvester/mylocationsengine/src/maptileinterface.cpp
changeset 17 0f22fb80ebba
child 20 cd10d5b85554
equal deleted inserted replaced
15:13ae750350c9 17:0f22fb80ebba
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Maptile interface source implementation for maptile
       
    15 *              service.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <EPos_CPosLandmark.h>
       
    20 #include <EPos_CPosLandmarkDatabase.h>
       
    21 #include <EPos_CPosLmItemIterator.h>
       
    22 #include <EPos_CPosLmOperation.h>
       
    23 #include <f32file.h>
       
    24 #include <bautils.h>
       
    25 #include "maptileinterface.h"
       
    26 #include "mylocationlogger.h"
       
    27 
       
    28 //Invalid latitude & longitude value
       
    29 const TReal KInvalidLatitudeLongitude = 200.00;
       
    30 const TInt KStreetLvelZoom = 14;
       
    31 const TInt KCityLevelZoom = 7;
       
    32 const TInt KMapTileSize= 256;
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CMapTileInterface::NewL()
       
    36 // Creates and returns the instance of CMapTileInterface
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CMapTileInterface* CMapTileInterface::NewL()
       
    40 {
       
    41     CMapTileInterface* self = new (ELeave) CMapTileInterface();
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop(self);
       
    45     return self;
       
    46 }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CMapTileInterface::~CMapTileInterface()
       
    50 // Destructor
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CMapTileInterface::~CMapTileInterface()
       
    54 {
       
    55     __TRACE_CALLSTACK;
       
    56    
       
    57     delete iFilePath;
       
    58     
       
    59     delete iMaptileGeocoder;
       
    60 }    
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMapTileInterface::CMapTileInterface()
       
    65 // Constructor
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CMapTileInterface::CMapTileInterface() :
       
    69            iMaptileGeocoder( NULL ), iFilePath( NULL ),iObserver(NULL)
       
    70 {
       
    71 }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CMapTileInterface::ConstructL()
       
    75 // Two phase constructor
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CMapTileInterface::ConstructL()
       
    79 {
       
    80     __TRACE_CALLSTACK;
       
    81 
       
    82     iMaptileGeocoder = CMaptileGeocoderPlugin::NewL();
       
    83     
       
    84     iMaptileGeocoder->SetMaptileGeocoderObserver( *this );
       
    85 }
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMapTileInterface::GetMapTileImageL()
       
    88 // Interface for requesting maptile image for a landmark object
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CMapTileInterface::GetMapTileImageL(const TDesC& aAddressDetails,
       
    92         const TDesC& aFilePath, MMapTileObserver* aObserver)
       
    93 {
       
    94     __TRACE_CALLSTACK;
       
    95     iObserver = aObserver;
       
    96     delete iFilePath;
       
    97     iFilePath = NULL;    
       
    98     iFilePath = HBufC::NewL(aFilePath.Length());
       
    99     iFilePath->Des().Copy(aFilePath);
       
   100     TConnectionOption conn = EInteractive;
       
   101     iMaptileGeocoder->GetCoordinateByAddressL(aAddressDetails, conn);
       
   102 }
       
   103 // -----------------------------------------------------------------------------
       
   104 // CMapTileInterface::GetMapTileImageL()
       
   105 // Interface for requesting maptile image for a landmark object
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CMapTileInterface::GetMapTileImageL(CPosLandmark* aLandmark,
       
   109         const TDesC& aFilePath, MMapTileObserver* aObserver)
       
   110 {
       
   111     __TRACE_CALLSTACK;
       
   112     iObserver = aObserver;
       
   113     delete iFilePath;
       
   114     iFilePath = NULL;    
       
   115     iFilePath = HBufC::NewL(aFilePath.Length());
       
   116     iFilePath->Des().Copy(aFilePath);
       
   117 
       
   118     TPtrC getStreet;
       
   119 
       
   120     aLandmark->GetPositionField(EPositionFieldStreet, getStreet);
       
   121 
       
   122     if (getStreet.Length() > 0)
       
   123     {
       
   124         iStreetAvailable = ETrue;
       
   125     }
       
   126 
       
   127     TConnectionOption conn = EInteractive;
       
   128 
       
   129 
       
   130     iMaptileGeocoder->GetCoordinateByAddressL(*aLandmark, conn);
       
   131 }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMapTileInterface::GetMapTileImageL()
       
   135 // Function for Retrieving latitude & longitude information
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CMapTileInterface::GetMapTileL(TReal aLatitude, TReal aLongitude)
       
   139 {
       
   140     __TRACE_CALLSTACK;//Notification to observer , to update contact db,
       
   141     iObserver->RestGeoCodeCompleted(aLatitude, aLongitude);
       
   142 
       
   143     TInt zoom = KCityLevelZoom;
       
   144     TInt size = KMapTileSize;
       
   145     if (iStreetAvailable)
       
   146     {
       
   147         zoom = KStreetLvelZoom;
       
   148     }
       
   149 
       
   150     iStreetAvailable = EFalse;
       
   151 
       
   152     TMapTileParam mapTileparam(aLatitude, aLongitude, zoom, size);
       
   153 
       
   154     iMaptileGeocoder->GetMapTileByGeoCodeL( mapTileparam, *iFilePath );
       
   155 }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CMapTileInterface::MapComplete()
       
   159 // Maptile retrievel notification
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CMapTileInterface::MapTileFetchingCompleted( TInt aErrCode, const TDesC& aMapTilePath )
       
   163 {
       
   164     __TRACE_CALLSTACK;
       
   165     MYLOCLOGSTRING1("MapComplete() status-%d ",aErrCode );
       
   166     iObserver->MapTilefetchingCompleted( aErrCode, aMapTilePath );
       
   167 
       
   168 }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CMapTileInterface::GeocodeComplete()
       
   172 // Geocode completion  notification
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CMapTileInterface::GeocodingCompleted(TInt aErrorcode,
       
   176         MAddressInfo& aAddressInfo)
       
   177 {
       
   178     __TRACE_CALLSTACK;
       
   179     TReal latitude, longitude;
       
   180     aAddressInfo.GetLatitude( latitude );
       
   181     aAddressInfo.GetLongitude( longitude );
       
   182     
       
   183     MYLOCLOGSTRING1("GeocodeCompleted() status-%d",aErrorcode);
       
   184     MYLOCLOGSTRING1("GeocodeCompleted() latitude-%f",latitude );
       
   185     MYLOCLOGSTRING1("GeocodeCompleted() longitude-%f",longitude );
       
   186 	
       
   187     if (aErrorcode == KErrNone)
       
   188     {
       
   189         if ( latitude != KInvalidLatitudeLongitude
       
   190                 && longitude != KInvalidLatitudeLongitude)
       
   191         {
       
   192             TRAPD( error, GetMapTileL(latitude, longitude) );
       
   193             if ( error != KErrNone )
       
   194             {
       
   195                 //Log error message
       
   196 				 MYLOCLOGSTRING1("GetMapTileL() status-%d",error);
       
   197 				 iObserver->MapTilefetchingCompleted(error, KNullDesC);
       
   198             }
       
   199         }
       
   200         else
       
   201         {
       
   202             iObserver->MapTilefetchingCompleted(KErrGeneral, KNullDesC);
       
   203         }
       
   204     }
       
   205     else
       
   206     {
       
   207         iObserver->MapTilefetchingCompleted(aErrorcode, KNullDesC);
       
   208 
       
   209     }
       
   210 }
       
   211