Home > Windows Phone > Get nearby locations using Bing maps – WP 8

Get nearby locations using Bing maps – WP 8

Using ‘Bing Maps Task’ we can get the nearby locations (i.e., Hospitals,Coffee shops or Shopping malls) on the Map.

Add a button to your XAML page and on ‘Click’ event handler place below code.

UI XAML

UI XAML

using Windows.Devices.Geolocation;

private async void btnMapTask_Click(object sender, RoutedEventArgs e)        {

// Get the Current location Coordinates

Geolocator geolocator = new Geolocator();

geolocator.DesiredAccuracyInMeters = 50;

Geoposition position = await geolocator.GetGeopositionAsync(

maximumAge: TimeSpan.FromMinutes(1), timeout: TimeSpan.FromSeconds(30));

// Initialize BingMapsTask

BingMapsTask bingMapsTask = new BingMapsTask();

// Pass the current location coordinates

bingMapsTask.Center = new GeoCoordinate(position.Coordinate.Latitude, position.Coordinate.Longitude);

bingMapsTask.ZoomLevel = 2;

// Search Term; To search coffee shops set ‘coffee’

bingMapsTask.SearchTerm = “hospital“;

bingMapsTask.Show();

}

When you click on the button, we will get below screen.

 

Allow load Map

Allow load Map

Once you click on ‘allow’ , we will get a bing map with nearest hospitals.

Nearest Hospitals

Nearest Hospitals

Also we need to enable following two Capabilities in application manifest file “WMAppManifest.xml”

1.ID_CAP_LOCATION
2.ID_CAP_MAP

🙂

Advertisement
Categories: Windows Phone Tags: , ,
  1. April 15, 2014 at 3:38 PM

    Thanks for the post. Above Code is working fine. We just need to enable following two Capabilities in application manifest file “WMAppManifest.xml”

    1.ID_CAP_LOCATION
    2.ID_CAP_MAP

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: