22 #include <EPos_CPosLmOperation.h> |
22 #include <EPos_CPosLmOperation.h> |
23 #include <f32file.h> |
23 #include <f32file.h> |
24 #include <bautils.h> |
24 #include <bautils.h> |
25 #include "maptileinterface.h" |
25 #include "maptileinterface.h" |
26 #include "mylocationlogger.h" |
26 #include "mylocationlogger.h" |
|
27 #include "mylocationsdefines.h" |
|
28 #include "lookupmaptiledb.h" |
|
29 #include <math.h> |
27 |
30 |
28 //Invalid latitude & longitude value |
31 //Invalid latitude & longitude value |
29 const TReal KInvalidLatitudeLongitude = 200.00; |
32 const TReal KInvalidLatitudeLongitude = 200.00; |
30 const TInt KStreetLvelZoom = 14; |
33 const TInt KStreetLvelZoom = 15; |
31 const TInt KCityLevelZoom = 7; |
34 const TInt KCityLevelZoom = 11; |
32 const TInt KMapTileSize= 256; |
35 const TInt KMapTileWidth= 330; |
|
36 const TInt KMapTileHeight= 128; |
|
37 const TInt KImagePathSize=36; |
|
38 const TInt KMapTileWidthHeight = 256 ; |
|
39 _LIT(KFileExtn, ".png"); |
33 |
40 |
34 // ----------------------------------------------------------------------------- |
41 // ----------------------------------------------------------------------------- |
35 // CMapTileInterface::NewL() |
42 // CMapTileInterface::NewL() |
36 // Creates and returns the instance of CMapTileInterface |
43 // Creates and returns the instance of CMapTileInterface |
37 // ----------------------------------------------------------------------------- |
44 // ----------------------------------------------------------------------------- |
87 iMaptileGeocoder = CMaptileGeocoderPlugin::NewL(); |
94 iMaptileGeocoder = CMaptileGeocoderPlugin::NewL(); |
88 |
95 |
89 iMaptileGeocoder->SetMaptileGeocoderObserver( *this ); |
96 iMaptileGeocoder->SetMaptileGeocoderObserver( *this ); |
90 } |
97 } |
91 // ----------------------------------------------------------------------------- |
98 // ----------------------------------------------------------------------------- |
92 // CMapTileInterface::GetMapTileImageL() |
99 // CMapTileInterface::GetGeoCodeFromAddressL() |
93 // Interface for requesting maptile image for a landmark object |
100 // Interface for requesting GEO fields for the given address |
94 // ----------------------------------------------------------------------------- |
101 // ----------------------------------------------------------------------------- |
95 // |
102 // |
96 void CMapTileInterface::GetMapTileImageL(const TDesC& aAddressDetails, |
103 void CMapTileInterface::GetGeoCodeFromAddressL(const TDesC& aAddressDetails, |
97 const TDesC& aFilePath, MMapTileObserver* aObserver) |
104 const TDesC& aFilePath, MMapTileObserver* aObserver) |
98 { |
105 { |
99 __TRACE_CALLSTACK; |
106 __TRACE_CALLSTACK; |
100 iObserver = aObserver; |
107 iObserver = aObserver; |
101 delete iFilePath; |
108 delete iFilePath; |
102 iFilePath = NULL; |
109 iFilePath = NULL; |
103 iFilePath = HBufC::NewL(aFilePath.Length()); |
110 iFilePath = HBufC::NewL(aFilePath.Length()); |
104 iFilePath->Des().Copy(aFilePath); |
111 iFilePath->Des().Copy(aFilePath); |
105 iStreetAvailable = EFalse; |
112 iStreetAvailable = EFalse; |
106 TConnectionOption conn = ESilent; |
113 iMaptileGeocoder->GetCoordinateByAddressL(aAddressDetails, ESilent); |
107 iMaptileGeocoder->GetCoordinateByAddressL(aAddressDetails, conn); |
114 |
108 } |
115 } |
109 // ----------------------------------------------------------------------------- |
116 // ----------------------------------------------------------------------------- |
110 // CMapTileInterface::GetMapTileImageL() |
117 // CMapTileInterface::GetGeoCodeFromAddressL() |
111 // Interface for requesting maptile image for a landmark object |
118 // Interface for requesting GEO fields for the given landmark adress |
112 // ----------------------------------------------------------------------------- |
119 // ----------------------------------------------------------------------------- |
113 // |
120 // |
114 void CMapTileInterface::GetMapTileImageL(CPosLandmark* aLandmark, |
121 void CMapTileInterface::GetGeoCodeFromAddressL(CPosLandmark* aLandmark, |
115 const TDesC& aFilePath, MMapTileObserver* aObserver) |
122 const TDesC& aFilePath, MMapTileObserver* aObserver) |
116 { |
123 { |
117 __TRACE_CALLSTACK; |
124 __TRACE_CALLSTACK; |
118 iObserver = aObserver; |
125 iObserver = aObserver; |
119 delete iFilePath; |
126 delete iFilePath; |
120 iFilePath = NULL; |
127 iFilePath = NULL; |
121 iFilePath = HBufC::NewL(aFilePath.Length()); |
128 iFilePath = HBufC::NewL(aFilePath.Length()); |
122 iFilePath->Des().Copy(aFilePath); |
129 iFilePath->Des().Copy(aFilePath); |
123 |
130 |
|
131 //Reset the street level available flag |
|
132 iStreetAvailable = EFalse; |
|
133 |
124 TPtrC getStreet; |
134 TPtrC getStreet; |
125 aLandmark->GetPositionField(EPositionFieldStreet, getStreet); |
135 aLandmark->GetPositionField(EPositionFieldStreet, getStreet); |
126 |
136 |
127 if (getStreet.Length() > 0) |
137 if (getStreet.Length() > 0) |
128 { |
138 { |
129 iStreetAvailable = ETrue; |
139 iStreetAvailable = ETrue; |
130 } |
140 } |
131 TConnectionOption conn = ESilent; |
141 iMaptileGeocoder->GetCoordinateByAddressL(*aLandmark, ESilent); |
132 iMaptileGeocoder->GetCoordinateByAddressL(*aLandmark, conn); |
|
133 } |
142 } |
134 |
143 |
135 // ----------------------------------------------------------------------------- |
144 // ----------------------------------------------------------------------------- |
136 // CMapTileInterface::GetMapTileImageL() |
145 // CMapTileInterface::GetMapTileImageL() |
137 // Function for Retrieving latitude & longitude information |
146 // Function for Retrieving latitude & longitude information |
138 // ----------------------------------------------------------------------------- |
147 // ----------------------------------------------------------------------------- |
139 // |
148 // |
140 void CMapTileInterface::GetMapTileL(TReal aLatitude, TReal aLongitude) |
149 void CMapTileInterface::GetMapTileL( const TReal& aLatitude, const TReal& aLongitude) |
141 { |
150 { |
142 __TRACE_CALLSTACK;//Notification to observer , to update contact db, |
151 __TRACE_CALLSTACK;//Notification to observer , to update contact db, |
143 iObserver->RestGeoCodeCompleted(aLatitude, aLongitude); |
|
144 TInt zoom = KCityLevelZoom; |
152 TInt zoom = KCityLevelZoom; |
145 TInt size = KMapTileSize; |
|
146 if (iStreetAvailable) |
153 if (iStreetAvailable) |
147 { |
154 { |
148 zoom = KStreetLvelZoom; |
155 zoom = KStreetLvelZoom; |
149 } |
156 } |
150 iStreetAvailable = EFalse; |
157 iStreetAvailable = EFalse; |
151 TMapTileParam mapTileparam(aLatitude, aLongitude, zoom, size); |
158 TMapTileParam mapTileparam(aLatitude, aLongitude, zoom, KMapTileWidth, KMapTileHeight ); |
152 iMaptileGeocoder->GetMapTileByGeoCodeL( mapTileparam, *iFilePath ); |
159 iMaptileGeocoder->GetMapTileByGeoCodeL( mapTileparam, *iFilePath ); |
153 } |
160 } |
154 |
161 |
155 // ----------------------------------------------------------------------------- |
162 // ----------------------------------------------------------------------------- |
156 // CMapTileInterface::MapComplete() |
163 // CMapTileInterface::MapComplete() |
160 void CMapTileInterface::MapTileFetchingCompleted( TInt aErrCode, const TDesC& aMapTilePath ) |
167 void CMapTileInterface::MapTileFetchingCompleted( TInt aErrCode, const TDesC& aMapTilePath ) |
161 { |
168 { |
162 __TRACE_CALLSTACK; |
169 __TRACE_CALLSTACK; |
163 MYLOCLOGSTRING1("MapComplete() status-%d ",aErrCode ); |
170 MYLOCLOGSTRING1("MapComplete() status-%d ",aErrCode ); |
164 iObserver->MapTilefetchingCompleted( aErrCode, aMapTilePath ); |
171 iObserver->MapTilefetchingCompleted( aErrCode, aMapTilePath ); |
165 |
172 } |
|
173 |
|
174 // ---------------------------------------------------------------------------- |
|
175 // CMapTileInterface::UpdateFilePathL() |
|
176 // Converts the geocoordinate to maptile pixel coordinate and updates the |
|
177 // file path to Maptilefolder\RowCol.png |
|
178 // ---------------------------------------------------------------------------- |
|
179 // |
|
180 void CMapTileInterface::UpdateFilePathL( const TReal& aLatitude, const TReal& aLongitude ) |
|
181 { |
|
182 TInt iZoomLvl = KCityLevelZoom; |
|
183 if ( iStreetAvailable ) |
|
184 iZoomLvl = KStreetLvelZoom; |
|
185 |
|
186 TInt totalTilesHorizontal = 1 << iZoomLvl; |
|
187 TInt totalTilesVertical = 1 << iZoomLvl; |
|
188 |
|
189 TInt totalMapWidth = totalTilesHorizontal * KMapTileWidthHeight; |
|
190 TInt totalMapHeight = totalTilesVertical * KMapTileWidthHeight; |
|
191 |
|
192 TReal pi = 3.14159265; |
|
193 |
|
194 TInt convertedx = (( aLongitude + 180.0) * totalMapWidth) |
|
195 / 360.0; |
|
196 TReal convertedtemp = log(tan(( aLatitude + 90) * pi |
|
197 / 360.0)); |
|
198 int convertedy = (1 - convertedtemp / pi) * totalMapHeight / 2.0; |
|
199 |
|
200 //Get the image row,col |
|
201 TInt iMapTileImageRow = convertedy / 256.0; |
|
202 TInt iMapTileImageCol = convertedx / 256.0; |
|
203 |
|
204 TBuf<KImagePathSize> mImagePath; |
|
205 |
|
206 mImagePath.AppendNum(iMapTileImageRow); |
|
207 mImagePath.AppendNum(iMapTileImageCol); |
|
208 mImagePath.Append(KFileExtn); |
|
209 |
|
210 iFilePath = iFilePath->ReAllocL(iFilePath->Length() + mImagePath.Length() ); |
|
211 iFilePath->Des().Append(mImagePath); |
166 } |
212 } |
167 |
213 |
168 // ----------------------------------------------------------------------------- |
214 // ----------------------------------------------------------------------------- |
169 // CMapTileInterface::GeocodeComplete() |
215 // CMapTileInterface::GeocodeComplete() |
170 // Geocode completion notification |
216 // Geocode completion notification |
185 if (aErrorcode == KErrNone) |
231 if (aErrorcode == KErrNone) |
186 { |
232 { |
187 if ( latitude != KInvalidLatitudeLongitude |
233 if ( latitude != KInvalidLatitudeLongitude |
188 && longitude != KInvalidLatitudeLongitude) |
234 && longitude != KInvalidLatitudeLongitude) |
189 { |
235 { |
190 TRAP_IGNORE( SetLandMarkDetailsL(aAddressInfo) ); |
236 TRAP_IGNORE( SetLandMarkDetailsL(aAddressInfo) ); |
191 TRAPD( error, GetMapTileL(latitude, longitude) ); |
237 TRAP_IGNORE( UpdateFilePathL( latitude, longitude ) ); |
192 if ( error != KErrNone ) |
238 |
193 { |
239 iObserver->GeoCodefetchingCompleted(KErrNone, latitude, longitude, iFilePath->Des()); |
194 //Log error message |
240 |
195 MYLOCLOGSTRING1("GetMapTileL() status-%d",error); |
|
196 iObserver->MapTilefetchingCompleted(error, KNullDesC); |
|
197 } |
|
198 } |
241 } |
199 else |
242 else |
200 { |
243 { |
201 iObserver->MapTilefetchingCompleted(KErrGeneral, KNullDesC); |
244 iObserver->GeoCodefetchingCompleted(KErrGeneral, |
202 } |
245 KInvalidLatitudeLongitude, KInvalidLatitudeLongitude, KNullDesC); |
|
246 } |
203 } |
247 } |
204 else |
248 else |
205 { |
249 { |
206 iObserver->MapTilefetchingCompleted(aErrorcode, KNullDesC); |
250 iObserver->GeoCodefetchingCompleted(aErrorcode, |
207 |
251 KInvalidLatitudeLongitude, KInvalidLatitudeLongitude, KNullDesC ); |
208 } |
252 } |
209 } |
253 } |
210 |
254 |
211 // ----------------------------------------------------------------------------- |
255 // ----------------------------------------------------------------------------- |
212 // CMapTileInterface::GetLandMarkDetails() |
256 // CMapTileInterface::GetLandMarkDetails() |