Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a map in a Windows Form app

Tags:

c#

winforms

maps

I built a Winform app several months ago that schedules appointments for repair techs. I'd like to update the app by adding a map for the customer's address on the customer form, and then print that map on the report the techs take when they leave the office.

I've been looking around but I haven't found a good solution for this yet.

I currently have an address for the customer. What I'd like to do is submit the address to one of the popular online map sites and get a minimap of the locale. I can almost do this with Google maps using their embedded link feature. I can get the following HTML after adding an address to their website:

<iframe width="300" height="300" frameborder="0" scrolling="no" 
   marginheight="0" marginwidth="0" 
   src="http://maps.google.com/maps?hl=en&amp;ie=UTF8&amp;t=h&amp;g=1193+Presque+Isle+Dr,+Port+Charlotte,+FL+33952&amp;s=AARTsJqsWtjYwJ7ucpVS6UU2EInkRk6JLA&amp;ll=27.012108,-82.087955&amp;spn=0.005735,0.006437&amp;z=16&amp;output=embed">
</iframe>

My first plan was to simply parse this HTML and insert whichever customer's address was needed in place this address, then show the result in a browser object on the form. However, if I change the address in the above iframe Google gives me a "Your client does not have permission to get URL ..." message.

I have no preference on which map service I ultimately use, the important thing is that the solution can't have an associated expenses and its usable from Windows forms.

Anyone got an ideas/recommendations/resources on how to tackle this?

Results:

I ended up using the control found here. I find it an "okay" solution... it's tedious to get working as the code does not work as-is. I'm pretty stunned to find that none of the popular map APIs support winforms.

like image 861
Sailing Judo Avatar asked Jan 08 '09 15:01

Sailing Judo


People also ask

How do I create a grid in Windows form?

Set global Windows Forms optionsIn Visual Studio, from the Tools menu, select Options. In the left pane of the Options dialog box, click Windows Forms Designer. In the right pane, under the Layout Settings heading, you can set the default grid settings for all the new forms you create.

What can you do with Windows Forms app?

Windows Forms contains a variety of controls that you can add to forms: controls that display text boxes, buttons, drop-down boxes, radio buttons, and even webpages. If an existing control doesn't meet your needs, Windows Forms also supports creating your own custom controls using the UserControl class.

What is map in C#?

AutoMapper in C# is a library used to map data from one object to another. It acts as a mapper between two objects and transforms one object type into another. It converts the input object of one type to the output object of another type until the latter type follows or maintains the conventions of AutoMapper.


2 Answers

There is some example code for developing a map viewer control (NB: I doubt this is strictly within their licence)

Otherwise, depending on your budget, you could use the MapPoint ActiveX control

like image 54
Rowland Shaw Avatar answered Oct 08 '22 08:10

Rowland Shaw


Just use the value inside the src="" as the location for a WebBrowser control directly, without the IFRAME.

OR

Build a minimal html document wrapping the IFRAME, write it out to a MemoryStream, re-seek it back to the start, and use the MemoryStream to set the WebBrowser control's DocumentStream property.

PW

like image 32
PolicyWatcher Avatar answered Oct 08 '22 08:10

PolicyWatcher