WPF Geocode radMap error

4 posts, 0 answers
  1. Lindell
    Lindell avatar
    3 posts
    Member since:
    Feb 2012

    Posted 18 Feb 2012 Link to this post

    Hi,

    I'm new to developing and have downloaded a trial of the WPF controls.I am trying to follow an example explaining how to use the geocode features. I have tried a few different ways but i always get the same error  "Object reference not set to an instance of an object." when it tries to run the code
    Me.geocodeProvider.GeocodeAsync(geocodeRequest)

    here is my full code any help would be greatly appreciated.

    XAML
    <Window x:Class="MainWindow"
               Title="MainWindow" Height="480" Width="620">
     
        <telerik:RadMap x:Name="RadMap" Height="540" VerticalAlignment="Top" ZoomLevel="7" Center="53.7500, -1.8333" MouseLocationIndicatorVisibility="Visible" NavigationVisibility="Collapsed" MapMouseDoubleClick="radMap1_MapMouseDoubleClick" MouseDoubleClickMode="None">
            <telerik:RadMap.Provider>
                <telerik:BingMapProvider Mode="Aerial" IsLabelVisible="True"
               IsTileCachingEnabled="True"
               ApplicationId="MY BING MAPS KEY" />
             
                </telerik:RadMap.Provider>
     
            <telerik:InformationLayer x:Name="informationlayer">
           
                </telerik:InformationLayer>
                 
     
                ></telerik:RadMap>   
             
       
     
    </Window>


    VB
    Imports Telerik.Windows.Controls.Map
     
    Partial Public Class MainWindow
        Dim geocodeProvider As BingGeocodeProvider
        Dim geocodeLocation As Location
     
        Public Sub New()
            InitializeComponent()
        End Sub
     
        Private Sub WindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
     
     
     
     
     
     
            ' Init geocode provider.
            geocodeProvider = New BingGeocodeProvider() With { _
             .ApplicationId = "MY BING MAPS KEY", _
             .MapControl = Me.radMap _
            }
            AddHandler Me.geocodeProvider.GeocodeCompleted, AddressOf Me.Provider_GeocodeCompleted
            ' Me.geocodeProvider.GeocodeCompleted += New EventHandler(Of GeocodeCompletedEventArgs)(AddressOf Provider_GeocodeCompleted)
        End Sub
     
     
        Private Sub BeginGeocodingRequest()
            Dim address As New Address() With { _
             .CountryRegion = "UK", _
             .PostalCode = "LS17 6HA" _
            }
     
            Dim geocodeRequest As New GeocodeRequest() With { _
             .Address = address _
            }
            Me.geocodeProvider.GeocodeAsync(geocodeRequest)
        End Sub
     
        Private Sub Provider_GeocodeCompleted(ByVal sender As Object, ByVal e As GeocodeCompletedEventArgs)
            Dim response As GeocodeResponse = e.Response
            If response.Results.Count > 0 Then
                Me.radMap.SetView(response.Results(0).BestView)
     
                ' Me.informationlayer.ItemsSource = response.Results(0).Locations
                Me.informationlayer.ItemsSource = response.Results(0).Locations
            End If
        End Sub
     
        Private Sub radMap1_MapMouseDoubleClick(ByVal sender As System.Object, ByVal eventArgs As Telerik.Windows.Controls.Map.MapMouseRoutedEventArgs)
            Dim address As New Address() With { _
                    .CountryRegion = "UK", _
                    .PostalCode = "LS17 6HA" _
                   }
     
            Dim geocodeRequest As New GeocodeRequest() With { _
             .Address = address _
            }
            Me.geocodeProvider.GeocodeAsync(geocodeRequest)
        End Sub
    End Class



    Thanks :)
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 22 Feb 2012 Link to this post

    Hi Lindell,

    It looks like you don't attach the Loaded event to your WindowLoaded event handler. So, the error occurs when you try to use unassigned geocodeProvider object.

    Greetings,
    Andrey Murzov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 22 Feb 2012 Link to this post

    Hi Lindell,

    It looks like you don't attach the Loaded event to your WindowLoaded event handler. So, the error occurs when you try to use unassigned geocodeProvider object.

    Greetings,
    Andrey Murzov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. Lindell
    Lindell avatar
    3 posts
    Member since:
    Feb 2012

    Posted 22 Feb 2012 Link to this post

    Thanks for your advice :)
Back to Top