This is a migrated thread and some comments may be shown as answers.

WPF Geocode radMap error

3 Answers 45 Views
Map
This is a migrated thread and some comments may be shown as answers.
Lindell
Top achievements
Rank 1
Lindell asked on 18 Feb 2012, 03:57 PM
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 :)

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 22 Feb 2012, 01:43 PM
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 >>
0
Yavor
Telerik team
answered on 22 Feb 2012, 01:44 PM
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 >>
0
Lindell
Top achievements
Rank 1
answered on 22 Feb 2012, 04:31 PM
Thanks for your advice :)
Tags
Map
Asked by
Lindell
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Yavor
Telerik team
Lindell
Top achievements
Rank 1
Share this question
or