MapForm.xaml.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Input;
  4. using System.Windows.Media.Imaging;
  5. using Google.Maps;
  6. using Google.Maps.StaticMaps;
  7. using InABox.Wpf;
  8. namespace PRSDesktop.Forms
  9. {
  10. /// <summary>
  11. /// Interaction logic for MapForm.xaml
  12. /// </summary>
  13. public partial class MapForm : ThemableWindow
  14. {
  15. String GOOGLE_KEY = "AIzaSyChZhoJCzeaOm8q2QMm2KJOgc26aCeopjQ";
  16. StaticMapRequest request = new StaticMapRequest();
  17. StaticMapService service = new StaticMapService();
  18. public BitmapImage ToImage(byte[] array)
  19. {
  20. using (var ms = new System.IO.MemoryStream(array))
  21. {
  22. var image = new BitmapImage();
  23. image.BeginInit();
  24. image.CacheOption = BitmapCacheOption.OnLoad; // here
  25. image.StreamSource = ms;
  26. image.EndInit();
  27. return image;
  28. }
  29. }
  30. public MapForm(double latitude, double longitude, DateTime timestamp)
  31. {
  32. InitializeComponent();
  33. GoogleSigned.AssignAllServices(new GoogleSigned(GOOGLE_KEY));
  34. request = new StaticMapRequest();
  35. String sLoc = String.Format("{0},{1}", latitude, longitude);
  36. Location location = new Location(sLoc);
  37. request.Center = location;
  38. request.Markers.Add(location);
  39. request.Scale = 2;
  40. request.Size = new MapSize(640, 640); // Convert.ToInt32(ActualWidth)-20, Convert.ToInt32(ActualHeight)-20);
  41. request.Zoom = 15;
  42. service = new StaticMapService();
  43. var imageSource = new BitmapImage();
  44. imageSource.BeginInit();
  45. imageSource.StreamSource = service.GetStream(request);
  46. imageSource.CacheOption = BitmapCacheOption.OnLoad;
  47. imageSource.EndInit();
  48. staticmap.Source = imageSource;
  49. TimeStamp.Content = String.Format("Last Updated {0:dd MMM yyy hh:mm:ss tt}", timestamp);
  50. }
  51. private void staticmap_MouseUp(object sender, MouseButtonEventArgs e)
  52. {
  53. Close();
  54. }
  55. }
  56. }