How to trace routes in a C# Windows Forms application from latitude and longitude

Asked

Viewed 752 times

1

Hello, I would like to know how to best display a route from the latitude and longitude that are in the database in a C# Windows Forms application. I’ve searched the web and I’ve managed to find something similar to what I need, https://social.msdn.microsoft.com/Forums/pt-BR/0e0b98ce-be58-4b8a-901d-8a05f9dd54f0/gerar-rotas-no-google-maps?forum=504 But I still can not understand much not. The code is getting as follows:

using System;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;

namespace GSD
{
    public class Class1{

        public Class1(){

        }

        public void AbreGoogleMaps(double _lat1, double _long1, double _lat2, double _long2)
        {
            string defaultBrowserPath = GetDefaultBrowserPath();

            try
            {
                Process.Start(defaultBrowserPath, string.Format("http://maps.google.com/maps?saddr={0},{1}&daddr={2},{3}", _lat1, _long1, _lat2, _long2));
            }

            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }

        private static string GetDefaultBrowserPath()
        {
            string key = @"htmlfile\shell\open\command";

            RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(key, false);

            return ((string)registryKey.GetValue(null, null)).Split('"')[1];
        }    
    }
}

1 answer

3


This implementation you demonstrated may even work, only it opens the user’s browser with the mapped route. This way you don’t have a desirable control of the implementations and makes it a little difficult to customize the maps. There is an Open Source library called Gmaps.NET (Great Maps .NET) that implements the map creation features in a form, there is also the possibility of using the google API to pick up the coordinates of the desired route, I believe that if you carry out an implementation uniting the two technologies, you can do something very complete and functional, below the links for verification:

https://github.com/radioman/greatmaps

https://developers.google.com/maps/documentation/geocoding/? hl=en

Browser other questions tagged

You are not signed in. Login or sign up in order to post.