简体   繁体   中英

How to display the multiple locations in map control(windows phone 8.1)

I am trying to develop an application in windows phone 8.1 with a map control. Google place api is used to get the nearby locations in the Json format. Now how to display them to my map control in windows phone application.

When I extract the Json format I got the below classes.

 public class Location
    {
        public double lat { get; set; }
        public double lng { get; set; }
    }

    public class Northeast
    {
        public double lat { get; set; }
        public double lng { get; set; }
    }

    public class Southwest
    {
        public double lat { get; set; }
        public double lng { get; set; }
    }

    public class Viewport
    {
        public Northeast northeast { get; set; }
        public Southwest southwest { get; set; }
    }

    public class Geometry
    {
        public Location location { get; set; }
        public Viewport viewport { get; set; }
    }

    public class OpeningHours
    {
        public bool open_now { get; set; }
        public List<object> weekday_text { get; set; }
    }

    public class Photo
    {
        public int height { get; set; }
        public List<string> html_attributions { get; set; }
        public string photo_reference { get; set; }
        public int width { get; set; }
    }

    public class Result
    {
        public Geometry geometry { get; set; }
        public string icon { get; set; }
        public string id { get; set; }
        public string name { get; set; }
        public string place_id { get; set; }
        public string reference { get; set; }
        public string scope { get; set; }
        public List<string> types { get; set; }
        public string vicinity { get; set; }
        public OpeningHours opening_hours { get; set; }
        public List<Photo> photos { get; set; }
        public double? rating { get; set; }
    }

    public class RootObject
    {
        public List<object> html_attributions { get; set; }
        public string next_page_token { get; set; }
        public List<Result> results { get; set; }
        public string status { get; set; }
    }

So I want to display every location in my map control with a pushpin.

在此处输入图片说明

In Geometry we have latitute and logitude values.How to place them in my map control

you have to do something like this first of all make two lists and pass locations to it like that

        public List<string> longt = new List<string>();
        public List<string> lati = new List<string>();

then for loop to show many icons on map like that

for (i = 0; i <=t.Longitudelist.Count-1 ; i++)
            {

                MapIcon mapIcon1 = new MapIcon();
                string latitudetxt;
                string longitudetxt;
                latitudetxt = t.Latitudelist[i].Text;
                longt.Add(latitudetxt);
                longitudetxt = t.Longitudelist[i].Text;
                lati.Add(longitudetxt);
                // mapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/StoreLogo.png"));
                mapIcon1.Location = new Geopoint(new BasicGeoposition()
                {

                   Latitude = Convert.ToDouble(longt[i]),
                   Longitude = Convert.ToDouble(lati[i])
                });
               // mapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/StoreLogo.png"));
                mapIcon1.NormalizedAnchorPoint = new Point(0.5, 0.5);
                Map.MapElements.Add(mapIcon1);

                var bt = new Button();
                buttonn.Add(bt);
                bt.Content = "";
                bt.Width = 30;
                bt.Height = 50;
                bt.Opacity = 10;
                bt.Content = i;
                 // button.
                this.Map.Children.Add(bt);
                // assign geoposition
                var position = new Geopoint(new BasicGeoposition()
                {
                    Latitude = Convert.ToDouble(longt[i]),
                    Longitude = Convert.ToDouble(lati[i])

                });
                MapControl.SetLocation(buttonn[i], position);
                var pointt=MapControl.GetLocation(bt);
                pointt.Position.Latitude.ToString();
                pointt.Position.Longitude.ToString();
                //longg= position.Position.Latitude;
                //latt = position.Position.Longitude;
              //  button.Tag = longg;

                MapControl.SetNormalizedAnchorPoint(bt, new Point(0.5, 0.5));
                MapControl.SetIsTemplateFocusTarget(bt, true);

                bt.Click += Button_Click;

                await Map.TrySetViewAsync(mapIcon1.Location, 18D, 0, 0, MapAnimationKind.Bow);

            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM