Click here to Skip to main content
15,880,891 members
Articles / Mobile Apps / Windows Phone 7

Bike In City with Windows Phone 7

Rate me:
Please Sign up or sign in to vote.
4.97/5 (62 votes)
5 Jan 2011CPOL33 min read 110.1K   3.1K   101  
Learn how to build a small mobile application to visualize data from the city bike sharing system. Get the nearest stations, find the number of free bikes, and compute directions to other stations.
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;
using Microsoft.Phone.Controls.Maps;
using BikeInCity.Model;
using System.Collections.Generic;
using System.Device.Location;

namespace BikeInCity.Utils
{
  public class LocationsConverter :IValueConverter
  {
    /// <summary>
    /// Converts a value.
    /// </summary>
    /// <param name="value">The value produced by the binding source.</param>
    /// <param name="targetType">The type of the binding target property.</param>
    /// <param name="parameter">The converter parameter to use.</param>
    /// <param name="culture">The culture to use in the converter.</param>
    /// <returns>
    /// A converted value. If the method returns null, the valid null value is used.
    /// </returns>
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      List<BikeCoordinate> coordinates = value as List<BikeCoordinate>;
      LocationCollection collection = new LocationCollection();
      foreach (BikeCoordinate coord in coordinates)
      {
        collection.Add(new GeoCoordinate(coord.Latitude,coord.Longitude));
      }
      return collection;
    }

    /// <summary>
    /// Converts a value.
    /// </summary>
    /// <param name="value">The value that is produced by the binding target.</param>
    /// <param name="targetType">The type to convert to.</param>
    /// <param name="parameter">The converter parameter to use.</param>
    /// <param name="culture">The culture to use in the converter.</param>
    /// <returns>
    /// A converted value. If the method returns null, the valid null value is used.
    /// </returns>
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      var collection = (LocationCollection)value;
      List<BikeCoordinate> coordinates = new List<BikeCoordinate>(collection.Count);
      foreach(GeoCoordinate coord in collection){
        coordinates.Add(new BikeCoordinate(coord.Latitude,coord.Longitude));
      }
      return coordinates;
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior) OCTO Technology
Czech Republic Czech Republic
Writing software at ITG RFQ-hub.
LinkedIn
Blog
GitHub
Articles at OCTO blog

Comments and Discussions