1

我之前从这个问题写过这个问题

我设法通过使用 Canvas 和 Path 作为我的自定义指南针来创建代码,如下所示:- 但是如何使用 GeoCoordinate 在画布顶部设置我的项目(在函数 CreateRadar 上)?以及如何将与指南针方向的关系与此项目联系起来?

下面是我的代码:

位置.xml

<results>
  <items id="458w281z-e7e923bd28614b33a1f8eb25ba75729d"
         latitude="3.1302" 
         longitude="101.58415" 
         distance="1374" 
         title ="Tropicana Golf &amp; Country Resort" 
         src="Images/tropicana.JPG"
         averageRating="0"
         icon="http://download.vcdn.nokia.com/p/d/places2/icons/categories/01.icon"
         vicinity="Jalan Kelab Tropicana 47810 Petaling Jaya"
         type="urn:nlp-types:place">        
        <category id="hotel" 
                  title="ATMs" 
                  href="http://demo.places.nlp.nokia.com/places/v1/categories/places/hotel?app_id=7vivA7jIFlZh9WX_B0cd&amp;app_code=6ptUAobtF0RFJ9CkfX7geg" 
                  type="urn:nlp-types:category" />
  </items>
<results>

Page1.xaml

 <radar:EllipsesWithEllipse Grid.RowSpan="2" Height="120" Width="120></radar:EllipsesWithEllipse>

用户控制 - EllipsesWithEllipse.xaml

<Canvas x:Name="compassHUD" Background="#3F000000" >
        <Canvas x:Name="CompassFace" Height="120" Width="120" Background="#3F000000">
            <Image Source="circle.png" Width="120" Height="120" Opacity="0.5" >
                <Image.Clip>
                    <EllipseGeometry RadiusX="120" RadiusY="120" Center="60,60"/>
                </Image.Clip>
            </Image>
            <Canvas x:Name="RadarGrid">
                <Ellipse Fill="Black" Width="10" Height="10"></Ellipse>
            </Canvas>
        </Canvas>
        <Path Stretch="Fill"  Margin="30,-2,0,0" Width="60" Height="65" StrokeThickness="1" StrokeLineJoin="Round" Stroke="#909090" 
              Fill="#909090" Opacity="0.5" UseLayoutRounding="False"  
              Data="F1 M149.55586,154.64513 L228,22.999901 C201,12.1666 174,1.3332601 147.5,2.0832601 C121,2.8332601 95,15.1666 69,27.499901 L149.55586,154.64513 z" />
    </Canvas>

EllipsesWithEllipse.xaml.cs

#region Properties
private PositionHelper pos_helper;
private GeoCoordinate currentLocation;
private List<Place> places;
#endregion

        public EllipsesWithEllipse()
        {
            InitializeComponent();
            pos_helper = new PositionHelper();
            currentLocation = new GeoCoordinate(Convert.ToDouble("3.33312"), Convert.ToDouble("101.6432"));
            CreateRadar(currentLocation);
        }
private void CreateRadar(GeoCoordinate currentPosition)
        {
            //char character;
            places = pos_helper.ParsePlaces(pos_helper.GetPlaces(currentPosition));

            double lon;
            double lat;
            Point point = new Point();

            foreach (Place place in places)
            {
                char ns = lat < 0 ? 'S' : 'N'; //Southern or Northern hemisphere?
        char ew = lon < 0 ? 'W' : 'E'; //Eastern or Western hemisphere?

                lon = Math.Abs(place.position.Longitude);
                lat = Math.Abs(place.position.Latitude);

                //convert lat and lon to y, x
                point =  ToCanvas(place.position.Longitude, place.position.Latitude);


                Ellipse e = new Ellipse();
                e.Fill = new SolidColorBrush(Colors.Black);
                e.Width = 8;
                e.Height = 8;


                RadarGrid.Children.Add(e);

                lon = Math.Abs(point.Y);
                lat = Math.Abs(point.X);

                Canvas.SetLeft(e, lon);
                Canvas.SetTop(e, lat);
            }
        }


        Point ToCanvas(double lat, double lon)
        {
            double x = 120 / 360; //canvas width was fixed
            x *= (lon - -180);
            double y = 120 / 180; //canvas height was fixed
            y *= -(lat + -90);
            return new Point(x, y);
        }

PositionHelper.cs

public static GeoCoordinate CurrentLocation { get; set; }
        public string GetPlaces(GeoCoordinate location)
        {
            CurrentLocation = location;

            Stream xmlfilePath = System.Windows.Application.GetResourceStream(new Uri("XMLFileCustom.xml", UriKind.Relative)).Stream;

            XElement appDataXml;
            appDataXml = XElement.Load(xmlfilePath);
            try
            {
                // Get a stream to the XML file which contains the data and load it into the XElement. 

            }
            catch { }
            finally
            {
                xmlfilePath.Close();
                xmlfilePath.Dispose();

            }

            return appDataXml.ToString();

        }

        public List<Place> ParsePlaces(string rawxml)
        {
            List<Place> places = new List<Place>();


                places = (from item in XElement.Parse(rawxml).Descendants("items").Elements("category")
                          select new Place()
                          {
                              id = (string)item.Parent.Attribute("id").Value,
                              title = (string)item.Parent.Attribute("title").Value,
                              image = (string)item.Parent.Attribute("src").Value,
                              averageRating = (double.Parse(item.Parent.Attribute("averageRating").Value)),
                              position = new GeoCoordinate(double.Parse(item.Parent.Attribute("latitude").Value), double.Parse(item.Parent.Attribute("longitude").Value), 0),
                              distance = (double.Parse(item.Parent.Attribute("distance").Value)),
                              href = (string)item.Parent.Attribute("href").Value,
                              icon = (string)item.Parent.Attribute("icon").Value,
                              vicinity = (string)item.Parent.Attribute("vicinity").Value,
                              type = (string)item.Parent.Attribute("type").Value,

                              category = new Category()
                              {
                                  href = (string)item.Attribute("href").Value,
                                  id = (string)item.Attribute("id").Value,
                                  title = (string)item.Parent.Attribute("title").Value,
                                  type = (string)item.Attribute("type").Value
                              }

                          }).ToList();

            return places;
        }
}


    [DataContract]
    public class Place
    {
        private GeoCoordinate _position;
        public GeoCoordinate position
        {
            get { return _position; }
            set { _position = value; }
        }

        private double _distance;
        public double distance
        {
            get { return _distance; }
            set { _distance = value; }
        }

        private string _title;
        public string title
        {
            get { return _title; }
            set { _title = value; }
        }

        private string _image;
        public string image
        {
            get { return _image; }
            set { _image = value; }
        }

        private double _averageRating;
        public double averageRating
        {
            get { return _averageRating; }
            set { _averageRating = value; }
        }

        private string _icon;
        public string icon
        {
            get { return _icon; }
            set { _icon = value; }
        }



        private string _vicinity;
        public string vicinity
        {
            get { return _vicinity; }
            set { _vicinity = value; }
        }

        private string _type;
        public string type
        {
            get { return _type; }
            set { _type = value; }
        }

        private string _href;
        public string href
        {
            get { return _href; }
            set { _href = value; }
        }

        private string _id;
        public string id
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _tag;
        public string tag
        {
            get { return _tag; }
            set { _tag = value; }
        }

        public Category category { get; set; }
    }

    [DataContract]
    public class Category
    {
        private string _id;
        public string id
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _title;
        public string title
        {
            get { return _title; }
            set { _title = value; }
        }

        private string _href;
        public string href
        {
            get { return _href; }
            set { _href = value; }
        }

        private string _type;
        public string type
        {
            get { return _type; }
            set { _type = value; }
        }

    }
4

0 回答 0