Advertisement
FANMixco

createMap.cs

Sep 22nd, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Device.Location;
  6. using Microsoft.Phone.Controls.Maps;
  7. using System.Windows;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using System.Windows.Shapes;
  11. using Microsoft.Phone.Controls;
  12.  
  13. namespace La_Ruta_Maya.classes
  14. {
  15.     public class Tuple<T1, T2, T3>
  16.     {
  17.         public T1 Latitude { get; set; }
  18.         public T2 Longitude { get; set; }
  19.         public T3 Name { get; set; }
  20.  
  21.         public Tuple(T1 item1, T2 item2, T3 item3)
  22.         {
  23.             Latitude = item1;
  24.             Longitude = item2;
  25.             Name = item3;
  26.         }
  27.     }
  28.  
  29.     class createMap
  30.     {
  31.         private Map mapLocation;
  32.         private double Latitude;
  33.         private double Longitude;
  34.         private GeoCoordinateWatcher myCoordinateWatcher;
  35.  
  36.         public createMap(Map temp)
  37.         {
  38.             this.mapLocation = temp;
  39.         }
  40.  
  41.         public void setCenter(double lat, double lon, double zoom, bool bar)
  42.         {
  43.             this.Latitude = lat;
  44.             this.Longitude = lon;
  45.  
  46.             this.mapLocation.Center = new GeoCoordinate(this.Latitude, this.Longitude);
  47.             this.mapLocation.ZoomLevel = zoom;
  48.             if (bar == true)
  49.                 mapLocation.ZoomBarVisibility = Visibility.Visible;
  50.            
  51.             myCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
  52.             myCoordinateWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(this.myCoordinateWatcher_PositionChanged);
  53.            
  54.         }
  55.  
  56.         private void myCoordinateWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
  57.         {
  58.             if (!e.Position.Location.IsUnknown)
  59.             {
  60.                 Latitude = e.Position.Location.Latitude;
  61.                 Longitude = e.Position.Location.Longitude;
  62.                 mapLocation.Center = new GeoCoordinate(Latitude, Longitude);
  63.             }
  64.         }
  65.  
  66.         public void addPushpins(List<Tuple<double, double, string>> Values)
  67.         {
  68.             foreach (Tuple<double, double, string> location in Values ){
  69.  
  70.                 ImageBrush ib = new ImageBrush();
  71.                 ib.ImageSource =
  72.                 new BitmapImage(new Uri("/images/ruin.png", UriKind.Relative));
  73.  
  74.                 Pushpin pp = new Pushpin();
  75.                 pp.Template = null;
  76.                 pp.Location = new GeoCoordinate( location.Latitude, location.Longitude);
  77.                 pp.Content = new Rectangle()
  78.                 {
  79.                     Fill = ib,
  80.                     Opacity = .8,
  81.                     Height = 30,
  82.                     Width = 26
  83.                 };
  84.  
  85.                 mapLocation.Children.Add(pp); //myMap is your map control                
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement