Display more than 10 results when searching using VB.Net and Bing Maps

311 views Asked by At

I created a vb.net code referencing the below link from Microsoft. https://msdn.microsoft.com/en-us/library/dd221354.aspx

Is there a way to get more than 10 results when searching for say pizza in say New York? If I search pizza in new york i only get a result of 10 locations. How can I get all of them. Also is it possible to get the address with in the request? Below is my code.

Imports Bing.SearchService

Public Class Form1

Private Sub btnGeoCode_Click(sender As System.Object, e As System.EventArgs) Handles btnGeoCode.Click
    test(TextBox1.Text)
End Sub

Public Sub test(ByVal keywordLocation As String)

    Dim Key As String = ""
    Dim searchRequest As New SearchRequest

    'credentials  
    searchRequest.Credentials = New SearchService.Credentials()
    searchRequest.Credentials.ApplicationId = Key

    ' Create the search query
    Dim ssQuery As New StructuredSearchQuery
    Dim parts As String() = keywordLocation.Split(";")

    ssQuery.Keyword = parts(0)
    ssQuery.Location = parts(1)
    searchRequest.StructuredQuery = ssQuery


    Dim searchService As New SearchServiceClient
    Dim SearchResponse As SearchResponse = searchService.Search(searchRequest)

    If SearchResponse.ResultSets(0).Results.Length > 0 Then

        Dim lstName As New ArrayList
        Dim lstAddress As New ArrayList

        For i As Integer = 0 To SearchResponse.ResultSets(0).Results.Length - 1

            lstName.Add(SearchResponse.ResultSets(0).Results(i).Name)
            lstAddress.Add(SearchResponse.ResultSets(0).Results(i).LocationData)

        Next

    End If

End Sub

End Class
2

There are 2 answers

2
rbrundritt On BEST ANSWER

It looks like you are using the of legacy Bing Maps SOAP services. You can return up to 25 results with the search service by setting the Count option:

searchRequest.SearchOptions = new SearchService.SearchOptions();
searchRequest.SearchOptions.Count = 25;

There is no option to have the address for the "where" component of the query returned. However, you can look at the parsed query value and that may provide the information you need. You can geocode that information if you want a center coordinate.

All this said, the Bing Maps Soap Services are nearing end of life and will be deprecated at the end of June 2017. These services were replaced by the Bing Maps REST services about 6 years ago. However, there is no service that provides free form queries for points of interest and business listings. There is a separate service where you can search against data sources doing nearby searches and filter based on category. You would geocode the "where" part of the query first then use its coordinate to do a radial search for nearby points of interest. Here are some useful resources on this:

https://msdn.microsoft.com/en-us/library/ff701713.aspx

https://github.com/Microsoft/BingMapsRESTToolkit/

https://msdn.microsoft.com/en-us/library/hh478189.aspx

https://msdn.microsoft.com/en-us/library/gg585126.aspx

https://code.msdn.microsoft.com/Augmented-Reality-with-bcb17045?redir=0 (shows how to use the Bing Spatial Data Services in .NET)

Currently there isn't a .NET toolkit for the Bing Spatial Data Services, but their will be one soon.

0
Shadow Fiend On

can you please do this.

Public Sub test(ByVal keywordLocation As String)

    Dim Key As String = ""
    Dim searchRequest As New SearchRequest

    'credentials  
    searchRequest.Credentials = New SearchService.Credentials()
    searchRequest.Credentials.ApplicationId = Key

    ' Create the search query
    Dim ssQuery As New StructuredSearchQuery
    Dim parts As String() = keywordLocation.Split(";")

    ssQuery.Keyword = parts(0)
    ssQuery.Location = parts(1)
    searchRequest.StructuredQuery = ssQuery


    Dim searchService As New SearchServiceClient
    Dim SearchResponse As SearchResponse = searchService.Search(searchRequest)

    If SearchResponse.ResultSets(0).Results.Length > 0 Then

        Dim lstName As New ArrayList
        Dim lstAddress As New ArrayList


            lstName.Add(SearchResponse.ResultSets(0).Results(i).Name)
            lstAddress.Add(SearchResponse.ResultSets(0).Results(i).LocationData)



    End If

End Sub

End Class