我正在尝试使用地图控件在Windows Phone 8.1中开发应用程序。 Google place api用于获取Json格式的附近位置。现在如何在Windows Phone应用程序中将它们显示到我的地图控件。
当我提取Json格式时,我得到了以下类。
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; }
}
所以我想用图钉显示地图控件中的每个位置。
在Geometry中,我们有latitute和logitude值。如何将它们放在我的地图控件中
答案 0 :(得分:1)
你必须做这样的事情首先制作两个列表并将位置传递给它
public List<string> longt = new List<string>();
public List<string> lati = new List<string>();
然后循环在地图上显示许多图标
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);
}
答案 1 :(得分:-1)