ErocM
ErocM

Reputation: 4662

How do I open up Microsoft Maps from a console application

I'm using .Net 5 and I'm trying create a simple application that calls the Microsoft Maps from this console application.

I started with this code:

static void Main(string[] args)
{
  Console.WriteLine("Hello World!");

  Uri uri = new Uri("bingmaps:?rtp=adr.Mountain%20View,%20CA~adr.San%20Francisco,%20CA&mode=d&trfc=1");
  var launcherOptions = new System.Windows.System.LauncherOptions();
  launcherOptions.TargetApplicationPackageFamilyName = "Microsoft.WindowsMaps_8wekyb3d8bbwe";
  await Launcher.LaunchUriAsync(uri, launcherOptions);
}

but I cannot find System.Windows.System to make it work. Where can I find this namespace or should I be going about this another way?

Upvotes: 0

Views: 155

Answers (1)

amirhosein adlfar
amirhosein adlfar

Reputation: 181

this is a console app not a windows app if you want use windows lib you must add them to project or you can use this code :
for first i tried run map directly from app but its have some limits so i did that with cmd.exe

string a = "bingmaps:?rtp=adr.Mountain%20View,%20CA~adr.San%20Francisco,%20CA&mode=d&trfc=1";
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe"); 
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine($"start {a}");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();

its worked for me

Upvotes: 1

Related Questions