Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi

I am newbie to C# and would like to know how to direct the output of the sql query to open the google maps


My SQL query will come out with the longitude and latitude and I want to use this output ( the latitude and longitude data ) and open a google maps automatically using a windows form application

Thanks

k
Posted
Updated 11-Oct-13 23:25pm
v2

You can build the appropriate URL to google maps (see their help topic on coordinates[^]) and then pass that through the Start method in the System.Diagnostics.Process class.

C#
Process.Start("https://maps.google.com/maps?q=%2B38%C2%B0+34'+24.00%22,+-109%C2%B0+32'+57.00%22");


The above corresponds to the example coordinates they provide in their help topic.
 
Share this answer
 
Comments
kiwirk 11-Oct-13 23:15pm    
Thanks mate .

As I mentioned that I am newbie ,I am not sure how to pass the result coming from the sql query to the search string ? currently when I do a query - I can get the output on to a windows form and instead of that I want to open a windows form automatically with googlemaps.com with the latitude and longitude as the search string

I mean how can I supply the search string using my sql query

https://maps.google.com/maps?q "search string ( latitude and longitude from sql query")

rk
There's no reason you cannot extrapolate based on what I provided. However, the Process.Start method is for pulling up a new browser. Based on your new information you want it to display on the form. To do that you want a WebBrowser control added to your Windows form. I'd recommend setting the ScriptErrorsSuppressed property to true to avoid any incompatibilities.

Here are some instructions:

1. Get your coordinates (I'm assuming degree-minute-second +-), you'll need to make your own adjustments if that's not your format. You can get that information based on the Google help document I linked to in my first reply.

2. Add the coordinates to your base URL string. The following code will do that. You can put this method in a static class.
C#
public static string BuildUrl(string coord)
{
   string googleFmt = "https://maps.google.com/maps?q={0}&um=1&ie=UTF-8&sa=N&tab=wl";
   string url = string.Format(googleFmt, coord);

   url = url.Replace("+", "ADD").Replace(" ", "+");
   url = Uri.EscapeUriString(url);
   url = url.Replace("ADD", "%2B");

   return url;
}


3. Call the Navigate method on the WebBrowser control.
C#
string url = UrlBuilder.BuildUrl(coord);
webBrowser1.Navigate(url);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900