RadMap with ListBox of Locations

2 posts, 0 answers
  1. Kurt
    Kurt avatar
    26 posts
    Member since:
    Mar 2009

    Posted 10 Oct 2010 Link to this post


    I'm trying to get a slight variation on one of your demos working, but I'm somewhat stumped.  I'm returning a description, latiitude and longitude list and while it is adding the Location objects to the list box (it moves to them when they are clicked on), the description is left blank.  Any ideas why my code is not working?  By the way, I tried figuring out my problem in the documentation, but since it is all in C#, it's useless.  Thanks ahead.

    Private Sub DoIT(ByVal sender As Object, ByVal e As ProjectsListCompletedEventArgs)
            Dim providerMode As MapMode = MapMode.Aerial
            Dim isLabelVisible As Boolean = True
            Dim provider As MapProviderBase
            provider = New BingMapProvider(providerMode, isLabelVisible, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
            With RadMap1
                .ZoomBarVisibility = Windows.Visibility.Collapsed
                .DistanceUnit = DistanceUnit.Mile
                .NavigationVisibility = Windows.Visibility.Collapsed
                .ScaleVisibility = Windows.Visibility.Collapsed
                .CommandBarVisibility = Windows.Visibility.Collapsed
                .Provider = provider
            End With
            For Each result In e.Result
                Dim pinPoint As MapPinPoint = New MapPinPoint
                With pinPoint
                    .Background = New SolidColorBrush(Colors.White)
                    .Foreground = New SolidColorBrush(Colors.Blue)
                    .FontSize = 10
                    .Text = result.ProjectName
                End With
                MapLayer.SetLocation(pinPoint, New Location(result.ProjectLat, result.ProjectLong))
                '*****Location works but description is not shown for some reason*********
                Dim loc As New Location
                With loc
                    .Description = "TEST"
                    .Latitude = result.ProjectLat
                    .Longitude = result.ProjectLong
                End With
            '*****Displays name, but of course, location doesn't work*********
            'ProjectBox.ItemsSource = e.Result
            'ProjectBox.DisplayMemberPath = "ProjectName"
        End Sub
  2. Andrey
    Andrey avatar
    1681 posts

    Posted 13 Oct 2010 Link to this post

    Hi Kurt,

    You didn't provide your XAML, but I can assume that you didn't use any DataTemplate for items in your ListBox. By default ListBox control uses string representation of the object (result of the ToString() call) added to the items collection. The ToString() method of the Location class returns values of the Latitude and Longitude properties only. So you don't see any description there. You have to specify data template which will be used by ListBox to represent Location items. For example:

    <UserControl x:Class="Telerik.RadMap.Silverlight.VB.MainPage"
                 Width="600" Height="400">
            <DataTemplate x:Key="ProjectItemTemplate">
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    <TextBlock Grid.Row="0" 
                               Text="Latitude:" />
                    <TextBlock Grid.Row="0" 
                               Text="{Binding Path=Latitude}" />
                    <TextBlock Grid.Row="1" 
                               Text="Longitude:" />
                    <TextBlock Grid.Row="1" 
                               Text="{Binding Path=Longitude}" />
                    <TextBlock Grid.Row="2" 
                               Text="Description:" />
                    <TextBlock Grid.Row="3" 
                               Text="{Binding Path=Description}" />
        <Grid x:Name="LayoutRoot" Background="White">
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            <telerik:RadMap x:Name="RadMap1">
                    <telerik:OpenStreetMapProvider />
                <telerik:InformationLayer  Name="informationLayer">
            <ListBox Name="ProjectBox" 
                     ItemTemplate="{StaticResource ProjectItemTemplate}"></ListBox>

    Kind regards,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top