Thursday, May 10, 2012

LocationServices for Windows Phone: getting media from Instagram based on location

Just a few minutes ago I pushed updates to the Instagram part of the framework, here’s a quick example of getting media based on a location:

        public MainViewModel()
        {
            this.instagramservicelayer = new Service.Instagram.Reactive.ServiceLayer();
        }

        private ObservableCollection<GenericPivotItem> pivotItems;
        public ObservableCollection<GenericPivotItem> PivotItems { get { if (pivotItems == null) pivotItems = new ObservableCollection<GenericPivotItem>(); return pivotItems; } set { pivotItems = value; } }

        public Service.Instagram.Reactive.ServiceLayer instagramservicelayer { get; private set; }

        private void WireInstagramPivotItem()
        {
            IsDataLoading = true;
            GenericPivotItem instagram = new GenericPivotItem() { Header = "photos", Source = "instagram" };
            var rxinstagram = instagramservicelayer.GetMediaByLocation(new Usoniandream.WindowsPhone.LocationServices.SearchCriterias.Instagram.MediaByLocation(new GeoCoordinate(40.74917, -73.98529)))
                .Take(20)
                .ObserveOnDispatcher()
                .Finally(() =>
                {
                    PivotItems.Add(instagram);
                    IsDataLoading = false;
                })
                .Subscribe(
                // result
                    x =>
                    {
                        instagram.Items.Add(x);
                    },
                // exception
                    ex =>
                    {
                        MessageBox.Show(ex.Message);
                    });

        }

with the result as seen below (don’t pay attention to the lack of design):

instagram

NOTE: the project currenty holds a local version of the RestSharp dll located in the lib folder. This is due to the fact that the JsonDeserializer in RestSharp was throwing InvalidCastExceptions when parsing certain types of json result. I’ve updated the JsonDeserializer in this local version.

The framework libraries, source code and sample app are all on GitHub: http://peterdrougge.github.com/Usoniandream.WIndowsPhone.LocationServices/

No comments: