Performing local searches with BingMapsTask

The BingMapsTask is similar to the BingMapsDirectionsTask Launcher, except for the difference that BingMapsTask launches the Bing Maps app from the Windows Phone, and can allow it to be pre-populated with a search keyword or mark locations on the map.

We can modify the previous example to use BingMapsTask and populate a search result for Pizza when the hyperlink button Search for Pizza is clicked or touched:

  1. Create a copy of our HelloMaps-Pushpin project and rename it HelloMaps-Search.
  2. Import the Microsoft.Phone.Tasks namespace.
  3. Declare an instance of BingMapsTask in your main class as:
    BingMapsTask myBingMapsTask;
    
  4. In the MainPage() constructor, we instantiate myBingMapsTask, center it to a position near Redmond, and finally define the search term as Pizza using the following lines of code:
    // Show Bing Maps and search for Pizza
    myBingMapsTask = new BingMapsTask();
    myBingMapsTask.Center = new GeoCoordinate
    (47.6601, -122.13333);
    myBingMapsTask.SearchTerm = "Pizza";
    // End of Bing Maps
    
  5. Add the Click() method of hyperlinkButton1 as:
    private void hyperlinkButton1_Click(object sender,
    RoutedEventArgs e)
    {
    myBingMapsTask.Show();
    }
    
  6. Running the app produces the following result:
    Performing local searches with BingMapsTask

    Note

    Memory allocated for a BingMapsTask does not count towards the total memory usage of your application. So try to use BingMapsTask instead of the Bing Maps Silverlight Control in your memory constraint devices/applications.

You can find this example project in the code files for the book under Chapter 3, titled HelloMaps-Search.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.79.241