none
How to launch bing map from windows portable class library RRS feed

  • Question

  • I have a requirement to launch Bing map from windows portable class library with current location.

    Does anyone know how to do that ?

    Thanks in advance.

    Tuesday, May 20, 2014 11:57 AM

Answers

  • If you want to bring up the maps app, just call LaunchUriAsynch from your library.

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh701480.aspx

    The bingmaps protocol is documented here:

    http://msdn.microsoft.com/en-us/library/windows/apps/jj635237.aspx

    Tuesday, May 20, 2014 5:06 PM
    Moderator
  • Window.System should already be available in your class in the shared folder of a universal app. Here is an example class I put together to test this out:

    using System;
    
    namespace App3
    {
        public static class MapLauncher
        {
            private static string baseUri = "bingmaps:?";
    
            public static void LaunchMap(double latitude, double longitude, int? zoom)
            {
                string uri = string.Format("{0}cp={1:N5}~{2:N5}", baseUri, latitude, longitude);
    
                if (zoom.HasValue)
                {
                    uri += "&lvl=" + zoom;
                }
    
                Launch(new Uri(uri));
            }
    
            public static void LaunchMap(string where, int? zoom)
            {
                string uri = baseUri + "where=" + Uri.EscapeDataString(where);
    
                if (zoom.HasValue)
                {
                    uri += "&lvl=" + zoom;
                }
    
                Launch(new Uri(uri));
            }
    
            public static void LaunchRoute(string start, string end)
            {
                string uri = string.Format("{0}rtp=adr.{1}~adr.{2}", baseUri, Uri.EscapeDataString(start), Uri.EscapeDataString(end));
    
                Launch(new Uri(uri));
            }
    
            private static async void Launch(Uri uri)
            {       
                // Launch the URI
                var success = await Windows.System.Launcher.LaunchUriAsync(uri);
    
                if (success)
                {
                    // URI launched
                }
                else
                {
                    // URI launch failed
                }
            }
        }
    }
    


    http://rbrundritt.wordpress.com

    Wednesday, May 21, 2014 9:44 AM

All replies

  • If you want to bring up the maps app, just call LaunchUriAsynch from your library.

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh701480.aspx

    The bingmaps protocol is documented here:

    http://msdn.microsoft.com/en-us/library/windows/apps/jj635237.aspx

    Tuesday, May 20, 2014 5:06 PM
    Moderator
  • Thanks for quick reply.

    Now my problem is I cannot add Windows.System reference inside my portable class library/windows class library.

    Wednesday, May 21, 2014 7:44 AM
  • Window.System should already be available in your class in the shared folder of a universal app. Here is an example class I put together to test this out:

    using System;
    
    namespace App3
    {
        public static class MapLauncher
        {
            private static string baseUri = "bingmaps:?";
    
            public static void LaunchMap(double latitude, double longitude, int? zoom)
            {
                string uri = string.Format("{0}cp={1:N5}~{2:N5}", baseUri, latitude, longitude);
    
                if (zoom.HasValue)
                {
                    uri += "&lvl=" + zoom;
                }
    
                Launch(new Uri(uri));
            }
    
            public static void LaunchMap(string where, int? zoom)
            {
                string uri = baseUri + "where=" + Uri.EscapeDataString(where);
    
                if (zoom.HasValue)
                {
                    uri += "&lvl=" + zoom;
                }
    
                Launch(new Uri(uri));
            }
    
            public static void LaunchRoute(string start, string end)
            {
                string uri = string.Format("{0}rtp=adr.{1}~adr.{2}", baseUri, Uri.EscapeDataString(start), Uri.EscapeDataString(end));
    
                Launch(new Uri(uri));
            }
    
            private static async void Launch(Uri uri)
            {       
                // Launch the URI
                var success = await Windows.System.Launcher.LaunchUriAsync(uri);
    
                if (success)
                {
                    // URI launched
                }
                else
                {
                    // URI launch failed
                }
            }
        }
    }
    


    http://rbrundritt.wordpress.com

    Wednesday, May 21, 2014 9:44 AM
  • Thanks for reply.

    But my problem is still the same.

    I have created a new application -> Visual C# -> Portable class library ->  Target framework as .Net 4.5 and higher and windows store app (Windows 8 and higher).

    Now If I try to run the above application it gives me error as application doesn't get reference of Windows.System namespace. If I go to add the same reference it is not present in in the list.

    I have also tried by creating a class library targeting to windows only but there also I am facing the same issue.

     

    Wednesday, May 21, 2014 10:50 AM
  • Ok. I see you problem. You need to create a Universal App, not a portable class library. Portable class libraries can be used not only in Windows and Windows Phone apps but in WPF, console apps, Silverlight and I believe Xbox at some point. Windows and Windows Phone are the only platforms that have maps built into them that you can launch. I have put together a complete code sample of how to do this here: http://code.msdn.microsoft.com/Launching-Maps-in-a-9daeaef4

    http://rbrundritt.wordpress.com

    Wednesday, May 21, 2014 2:32 PM
  • Thanks for reply

    I am creating a windows 8 tablet app using cross platform tool. From that tool I can't open bing map directly . So I want to create a windows class library which can open Bing map with current location. I will use this library as FFI in my application.


    Tuesday, May 27, 2014 4:50 PM
  • Look at the code sample I provided. The MapLauncher class I provided can be used in a Windows class library.

    http://rbrundritt.wordpress.com

    Tuesday, May 27, 2014 6:15 PM
  • I have tried  sample by creating a windows class library as well as windows portable class library. But in both cases I am unable to find Windows.System assembly reference due to which  Windows.System.Launcher function doesn't work.

    So it is not possible to invoke this function from windows class library/windows portable class library ? If not is there any alternate solution to launch bing map from these library?

    As I stated earlier "I am creating a windows 8 tablet app using cross platform tool. From that tool I can't open bing map directly . So I want to create a windows class library which can open Bing map with current location. I will use this library as FFI in my application."

    Thanks in advance.

    Thursday, May 29, 2014 9:35 AM
  • Surprise it doesn't work in a windows class library. Must be missing a reference. I came across this post which might be useful http://stackoverflow.com/questions/17943929/portable-class-libraries-and-webbrowsertask-vs-windows-system-launcher

    http://rbrundritt.wordpress.com

    Thursday, May 29, 2014 10:09 AM
  • Still not find any solution. Can you tell me where can I post this issue.

    Many Thanks 

    Friday, May 30, 2014 12:07 PM