BREW平臺上如何通過GPS設備獲取經緯度
1 typedef struct _App {
2 AEEApplet a ; // First element of this structure must be AEEApplet
3 AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
4 Common common;
5 // add your own variables here
6
7 //有關GPS的變量
8 IPosDet* posdet;
9 AEEGPSInfo gpsinfo;
10
11 char latchar[64];
12 char lonchar[64];
13
14 } App;
15
16
17 //GPS
18 static void GetGPS(App* app);
19 static void OnGPSNotify(App* app);
20
21 //初始化GPS相關的變量
22 static boolean OnAppStart(App* app)
23 {
24 IDisplay* display = app->a.m_pIDisplay;
25 IShell* shell = app->a.m_pIShell;
26
27 app->posdet = NULL;
28 ISHELL_CreateInstance(app->a.m_pIShell, AEECLSID_POSDET, (void**)&app->posdet);
29
30 return TRUE;
31 }
32
33 //獲取GPS
34 static void GetGPS(App* app)
35 {
36 int ret;
37 char buffer[80];
38
39
40 CALLBACK_Init(&app->callback, (PFNNOTIFY)OnGPSNotify, (void*)app);
41
42 ret = IPOSDET_GetGPSInfo(app->posdet, AEEGPS_GETINFO_LOCATION, AEEGPS_ACCURACY_LEVEL6, &app->gpsinfo, &app->callback);
43 switch (ret) {
44 case EPRIVLEVEL:
45 STRCPY(buffer, "EPRIVLEVEL");
46 break;
47
48 case EBADPARM:
49 STRCPY(buffer, "EBADPARM");
50 break;
51
52 case EUNSUPPORTED:
53 STRCPY(buffer, "EUNSUPPORTED");
54 break;
55
56 case EFAILED:
57 STRCPY(buffer, "EFAILED");
58 break;
59
60 case SUCCESS:
61 STRCPY(buffer, "SUCCESS");
62 break;
63
64 default:
65 STRCPY(buffer, "DEFAULT");
66 break;
67 }
68
69 if (ret != SUCCESS)
70 {
71 CALLBACK_Cancel(&app->callback);
72 }
73 return;
74 }
75
76 //GPS的回調函數
77 static void OnGPSNotify(App* app)
78 {
79 char szLat[32] = {0};
80 char szLon[32] = {0};
81 char szBuf[64] = {0};
82 AECHAR latwchar[64] = {0};
83 AECHAR lonwchar[64] = {0};
84
85 double lat = 0;
86 double lon = 0;
87
88 char m_gURL[256] = {0};
89
90 int pnInLen = 0;
91
92 MEMSET(app->latchar,0,64);
93 MEMSET(app->lonchar,0,64);
94
95
96 lat = WGS84_TO_DEGREES(app->gpsinfo.dwLat);
97 lon = WGS84_TO_DEGREES(app->gpsinfo.dwLon);
98 FLOATTOWSTR(lat, latwchar, 64);
99 FLOATTOWSTR(lon, lonwchar, 64);
100 WSTRTOSTR(latwchar, app->latchar, 64);
101 WSTRTOSTR(lonwchar, app->lonchar, 64);
102
103
104 SPRINTF(szLat, "Latitude(緯度) = %d", app->gpsinfo.dwLat);
105
106 SPRINTF(szLon, "Longitude(經度) = %d", app->gpsinfo.dwLon);
107
108
109 switch (app->gpsinfo.status) {
110 case AEEGPS_ERR_NO_ERR:
111 STRCPY(szBuf, "SUCCESS !");
112 break;
113
114 case AEEGPS_ERR_GENERAL_FAILURE:
115 STRCPY(szBuf, "AEEGPS_ERR_GENERAL_FAILURE");
116 break;
117
118 case AEEGPS_ERR_TIMEOUT:
119 STRCPY(szBuf, "AEEGPS_ERR_TIMEOUT");
120 break;
121
122 case AEEGPS_ERR_ACCURACY_UNAVAIL:
123 STRCPY(szBuf, "AEEGPS_ERR_ACCURACY_UNAVAIL");
124 break;
125
126 case AEEGPS_ERR_INFO_UNAVAIL:
127 STRCPY(szBuf, "AEEGPS_ERR_INFO_UNAVAIL");
128 break;
129
130 default:
131 STRCPY(szBuf, "DEFAULT");
132 break;
133 }
134 return;
135 }
2 AEEApplet a ; // First element of this structure must be AEEApplet
3 AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
4 Common common;
5 // add your own variables here

6
7 //有關GPS的變量
8 IPosDet* posdet;
9 AEEGPSInfo gpsinfo;
10
11 char latchar[64];
12 char lonchar[64];
13
14 } App;
15
16
17 //GPS
18 static void GetGPS(App* app);
19 static void OnGPSNotify(App* app);
20
21 //初始化GPS相關的變量
22 static boolean OnAppStart(App* app)
23 {
24 IDisplay* display = app->a.m_pIDisplay;
25 IShell* shell = app->a.m_pIShell;
26
27 app->posdet = NULL;
28 ISHELL_CreateInstance(app->a.m_pIShell, AEECLSID_POSDET, (void**)&app->posdet);
29
30 return TRUE;
31 }
32
33 //獲取GPS
34 static void GetGPS(App* app)
35 {
36 int ret;
37 char buffer[80];
38
39
40 CALLBACK_Init(&app->callback, (PFNNOTIFY)OnGPSNotify, (void*)app);
41
42 ret = IPOSDET_GetGPSInfo(app->posdet, AEEGPS_GETINFO_LOCATION, AEEGPS_ACCURACY_LEVEL6, &app->gpsinfo, &app->callback);
43 switch (ret) {
44 case EPRIVLEVEL:
45 STRCPY(buffer, "EPRIVLEVEL");
46 break;
47
48 case EBADPARM:
49 STRCPY(buffer, "EBADPARM");
50 break;
51
52 case EUNSUPPORTED:
53 STRCPY(buffer, "EUNSUPPORTED");
54 break;
55
56 case EFAILED:
57 STRCPY(buffer, "EFAILED");
58 break;
59
60 case SUCCESS:
61 STRCPY(buffer, "SUCCESS");
62 break;
63
64 default:
65 STRCPY(buffer, "DEFAULT");
66 break;
67 }
68
69 if (ret != SUCCESS)
70 {
71 CALLBACK_Cancel(&app->callback);
72 }
73 return;
74 }
75
76 //GPS的回調函數
77 static void OnGPSNotify(App* app)
78 {
79 char szLat[32] = {0};
80 char szLon[32] = {0};
81 char szBuf[64] = {0};
82 AECHAR latwchar[64] = {0};
83 AECHAR lonwchar[64] = {0};
84
85 double lat = 0;
86 double lon = 0;
87
88 char m_gURL[256] = {0};
89
90 int pnInLen = 0;
91
92 MEMSET(app->latchar,0,64);
93 MEMSET(app->lonchar,0,64);
94
95
96 lat = WGS84_TO_DEGREES(app->gpsinfo.dwLat);
97 lon = WGS84_TO_DEGREES(app->gpsinfo.dwLon);
98 FLOATTOWSTR(lat, latwchar, 64);
99 FLOATTOWSTR(lon, lonwchar, 64);
100 WSTRTOSTR(latwchar, app->latchar, 64);
101 WSTRTOSTR(lonwchar, app->lonchar, 64);
102
103
104 SPRINTF(szLat, "Latitude(緯度) = %d", app->gpsinfo.dwLat);
105
106 SPRINTF(szLon, "Longitude(經度) = %d", app->gpsinfo.dwLon);
107
108
109 switch (app->gpsinfo.status) {
110 case AEEGPS_ERR_NO_ERR:
111 STRCPY(szBuf, "SUCCESS !");
112 break;
113
114 case AEEGPS_ERR_GENERAL_FAILURE:
115 STRCPY(szBuf, "AEEGPS_ERR_GENERAL_FAILURE");
116 break;
117
118 case AEEGPS_ERR_TIMEOUT:
119 STRCPY(szBuf, "AEEGPS_ERR_TIMEOUT");
120 break;
121
122 case AEEGPS_ERR_ACCURACY_UNAVAIL:
123 STRCPY(szBuf, "AEEGPS_ERR_ACCURACY_UNAVAIL");
124 break;
125
126 case AEEGPS_ERR_INFO_UNAVAIL:
127 STRCPY(szBuf, "AEEGPS_ERR_INFO_UNAVAIL");
128 break;
129
130 default:
131 STRCPY(szBuf, "DEFAULT");
132 break;
133 }
134 return;
135 }
posted on 2010-04-05 00:11 Benjamin 閱讀(1661) 評論(8) 編輯 收藏 引用 所屬分類: 其他手機平臺