【问题标题】:Multimarkers in a bing Mapbing Map 中的多标记
【发布时间】:2016-01-21 16:02:00
【问题描述】:

我在为我的 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"
        }
    ]
}

问题是我在地图上只得到一个标记,它是经度、纬度的最后一个位置(根据我在地图上得到的 JSON 数据,只有具有此值的位置:

local_longi: "10.33699",
local_latit: "25.997745"

这是我在调试时得到的:

我在“位置”变量中得到所有结果,为什么我在地图中只得到一个标记

这是我遵循的教程: 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>

【问题讨论】:

    标签: c# win-universal-app uwp windows-10-universal


    【解决方案1】:

    嘿,尝试绑定 Pushpin 的 OberservableCollection(来自我的类​​)。

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 2020-10-06
      相关资源
      最近更新 更多