我在为bing地图中的每个位置添加标记时遇到问题,这是我的代码:
private async void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
await
// Need to get back onto UI thread before updating location information
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
async () =>
{
UriString4 = "my URL";
var http = new HttpClient();
http.MaxResponseContentBufferSize = Int32.MaxValue;
var response = await http.GetStringAsync(UriString4);
var rootObject = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);
Location[] location = new Location[int.Parse(rootObject.total)];
for (int i = 0; i < int.Parse(rootObject.total); i++)
{
//Get the current location
location[i] = new Location(rootObject.locals[i].local_latit,rootObject.locals[i].local_longi);
//Update the position of the GPS pushpin
MapLayer.SetPosition(GpsIcon, location[i]);
//Set the radius of the Accuracy Circle
GpsIcon.SetRadius(args.Position.Coordinate.Accuracy);
//Make GPS pushpin visible
GpsIcon.Visibility = Windows.UI.Xaml.Visibility.Visible;
//Update the map view to the current GPS location
MyMap.SetView(location[i], 17);
}
}));}
这是我想要获取local_longi和的JSON数据 每个地点的local_latit:
{
success : 1,
total : 2,
locals : [{
id_local : "59",
local_longi : "20",
local_latit : "25894"
}, {
id_local : "60",
local_longi : "10.33699",
local_latit : "25.997745"
}
]
}
问题是我在地图上只得到一个标记,这是经度,纬度的最后一个位置(根据我在Map上获得的数据,只有具有此值的位置:
local_longi: "10.33699",
local_latit: "25.997745"
我在&#34; location&#34;变量,为什么我在地图中只得到一个标记
这是我遵循的教程: https://blogs.bing.com/maps/2012/11/05/getting-started-with-bing-maps-windows-store-apps-native/
更新: 这是我的地图的xaml代码:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<m:Map Name="MyMap" Credentials="1m8dxWklva2lte3kYjkn~........" ZoomLevel="13" />
<CheckBox Content="GPS" Click="GPS_Checked"/>
</Grid>
答案 0 :(得分:1)
嘿试图绑定一个ObpinervableCollection的图钉(来自我的类)。
<Maps:MapItemsControl ItemsSource="{x:Bind ViewModel.Pushpins}">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate x:DataType="model:Pushpin">
<StackPanel Maps:MapControl.Location="{x:Bind Location, Converter={StaticResource PointConverter}}"
Maps:MapControl.NormalizedAnchorPoint="{x:Bind Path='', Converter={StaticResource DefaultAnchorPointConverter}}">
<TextBlock Text="{x:Bind Title}"
Foreground="Black" />
<Image Source="{x:Bind Path='', Converter={StaticResource PushpinConverter}}" />
</StackPanel>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>