Archive

Posts Tagged ‘WP 8’

Get nearby locations using Bing maps – WP 8

March 20, 2014 2 comments

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

🙂

Categories: Windows Phone Tags: , ,

Playing a song from library – WP8

Here is the logic to play a particular song from library.

Logic is to loop through all the songs in Media Library and if the song name matches to our song play the song.

string favoriteSong = “mySong.mp3”;

using (Microsoft.Xna.Framework.Media.MediaLibrary library = new Microsoft.Xna.Framework.Media.MediaLibrary())            {

foreach (var song in library.Songs)                {

if (song.Name == favoriteSong) {

FrameworkDispatcher.Update();

// Play the song

Microsoft.Xna.Framework.Media.MediaPlayer.Play(song);

break;

}

}

library.Dispose();

}

🙂