Pages

Tuesday, 18 September 2012

How to draw driving route direction with Bing maps in C#/XAML Windows 8 app


How to draw driving route direction with Bing maps in C#/XAML Windows 8 app
In one of my app, I have to give feature of drawing route direction with Bing maps. I found an example in JavaScript, but I want the same in C#/XAML. So Richard Brundritt helped me by providing the Bing Maps REST Service helper class, with that I managed to do it. Here I am posting the code. All REST links URL Templates cam be found here. Thanks to Richard Brundritt :)

protected async override void OnNavigatedTo(NavigationEventArgs e)
{
    Uri geocodeRequest = new Uri("http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=28.608280181884766,77.200813293457031&wp.1=19.072799682617188,72.882598876953125&optmz=distance&rpo=Points&key=YOUR_BING_MAP_KEY_HERE"); //Route Ahmedabad to Mumbai

    //Make a request and get the response
    BingMapsRESTService.Response r = await GetResponse(geocodeRequest);

    MapPolyline routeLine = new MapPolyline();
    routeLine.Locations = new LocationCollection();
    routeLine.Color = Colors.Blue;
    routeLine.Width = 5.0;

    int bound = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates.GetUpperBound(0);
    for (int i = 0; i < bound; i++)
    {
        routeLine.Locations.Add(new Location
        {
            Latitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][0],
            Longitude = ((BingMapsRESTService.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][1]
        });
    }
    MapShapeLayer shapeLayer = new MapShapeLayer();
    shapeLayer.Shapes.Add(routeLine);
    MyMap.ShapeLayers.Add(shapeLayer);
}


private async Task<Response> GetResponse(Uri uri)
{
    System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
    var response = await client.GetAsync(uri);
    using (var stream = await response.Content.ReadAsStreamAsync())
    {
        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
        return ser.ReadObject(stream) as Response;
    }
}


Monday, 17 September 2012

Data Presentation In HTML5/WinJS Metro App


Data Presentation In HTML5/WinJS Metro App
Inevitably, you’re going to have to make a choice about what control underlies this presentation of data, and eventually you’re going to have to implement it.

In this post, I’d like to do a little bit of a study into what control to choose when and why. As usual, I’ll be coming from an HTML/JS perspective, so if you’re wondering what your options are in XAML, Bing is your friend.

Read More

Creating an inline AppBar Button Style for your Win8 apps


Creating an inline AppBar Button Style for your Win8 apps
As you have probably read, the Metro Windows Store projects in Visual Studio now comes preloaded with a ton of styles for your AppBar. I love this style of button. You get the nice icon and text to indicate what the icon is supposed to mean (sometimes the icon can be confusing). Having both the icon and the text removes the need for users to hover over an icon to see what it’s suppose to be.

As awesome as the style is for buttons on the AppBar, they do have some limitations. They are big, and the text is on the bottom. This design makes it hard to put this style of icon in other parts of your app. Take a look at the Games app. Go all the way to the left and you’ll see your avatar along with ways to do more with your Xbox account. You accomplish these actions with buttons that look a lot like the AppBar buttons.

Read More

Authenticating an ASMX Web Service in SharePoint from a WinRT app


Where’s the CookieContainer?

Yes mate, I’ve had that question too.

We are creating a new application for Windows 8 and we need it to connect to our web services. Connecting to the anonymous methods was easy, but when it comes to authenticating the user the situation changes.

Read More
Web Informer Button