歡迎您光臨本站 註冊首頁

一百行代碼寫一個WP8路線跟蹤應用

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  

 


目錄
介紹
應用程序界面
定時執行
定位追蹤
設置地圖Pitch和Heading屬性
後台位置追蹤
Live Tile
總結


介紹
我從Windows Phone7 還在測試階段的時候就開始開發了,所以在Windows Phone 8 SDK開放后第一時間下載了。為了有趣,我決定創建一個簡單的跑步定位追蹤的應用來展示大量的特性,並且我將挑戰在100行代碼內完成此功能(不使用緊湊和可讀性差的代碼)
 


本文將通過我所開發的這個應用引導你深入探究 Windows Phone 8 中的以下特性:
新增的地圖控制項(擁有步行與三維路標功能)。
如何跟蹤用戶的位置,包括當其他程序運行時在後台跟蹤的情況。
在地圖上添加線條註釋一些3D地圖的特性,設置 pitch 與 heading 屬性。
使用新增的模板創建動態Tile雖然使用Windows Phone 7 開發一個這樣的路線跟蹤應用也是完全可以(商城裡已經有很多很棒的例子了),不過Windows Phone 8 中新增的特性與功能可以讓它的功能更加豐富。
注意哦: 我最初將本文發表在諾基亞開發者百科(Nokia Developer Wiki)上,不過在CodeProject

上我也分享了,在那裡你可以找到我寫的其他一些文章。

應用程序界面
這個程序的UI十分簡單,主要由一張全屏的地圖組成,地圖上面顯示跑步的統計信息,正如下面的截圖所示:

程序界面的XAML代碼如下:
01 <Grid util:GridUtils.RowDefinitions="Auto, *">

02  

03 <!-- title -->

04 <StackPanel Grid.Row="0" Margin="12,17,0,28">

05 <StackPanel Orientation="Horizontal">

06 <Image Source="/Assets/ApplicationIconLarge.png" Height="50"/>

07 <TextBlock Text="WP8Runner" VerticalAlignment="Center"

08 Margin="10 0 0 0"

09 FontSize="{StaticResource PhoneFontSizeLarge}"/>

10 </StackPanel>

11 </StackPanel>

12  

13 <!--ContentPanel - place additional content here-->

14 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

15  

16 <!-- the map -->

17 <maps:Map x:Name="Map"

18 ZoomLevel="16"/>

19  

20 <!-- 步行統計 -->

21 <Grid Background="#99000000" Margin="20"

22 VerticalAlignment="Bottom">

23 <Grid Margin="20"

24 util:GridUtils.RowDefinitions="40, 40, Auto"

25 util:GridUtils.ColumnDefinitions="*, *, *, *">

26  

27 <!-- 距離 -->

28 <TextBlock Text="Distance:"/>

29 <TextBlock Text="0 km" Grid.Column="1" x:Name="distanceLabel"

30 HorizontalAlignment="Center"/>

31  

32 <!-- 時間 -->

33 <TextBlock Text="Time:" Grid.Column="2"/>

34 <TextBlock Text="00:00:00" Grid.Column="3" x:Name="timeLabel"

35 HorizontalAlignment="Center"/>

36  

37 <!-- 卡路里 -->

38 <TextBlock Text="Calories:" Grid.Row="1"/>

39 <TextBlock Text="0" Grid.Column="1" x:Name="caloriesLabel"

40 HorizontalAlignment="Center" Grid.Row="1"/>

41  

42 <!-- 步幅 -->

43 <TextBlock Text="Pace:" Grid.Column="2" Grid.Row="1"/>

44 <TextBlock Text="00:00" Grid.Column="3" x:Name="paceLabel"

45 HorizontalAlignment="Center" Grid.Row="1"/>

46  

47 <Button Content="Start"



[火星人 ] 一百行代碼寫一個WP8路線跟蹤應用已經有421次圍觀

http://coctec.com/docs/program/show-post-71299.html