google map or image on form along zoomin zoomout

bcm

Well-known member
Joined
Aug 13, 2007
Messages
56
Programming Experience
Beginner
I want to create a program in VB.NET2005 windows application which will show google map on the form along with its contols of zoom.
OR
Also an image on form having zoomin and zoomout buttons.
Please Help!!!!
:confused:
 
You can do this two different ways as I see it, both involving using a WebBrowser control. When you go to http://maps.google.com/ there is a 'link to this page' where you can copy the provided Html and paste into your own webpage document, this may also be a local file, for example:
HTML:
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" 
src="http://maps.google.com/?ie=UTF8&z=4&om=0&ll=37.0625,-95.677068&output=embed&s=AARTsJqzARj-Z8VnW5pkPMLMmZbqrJcYpw">
</iframe>
If you save this to googlemap.html file you can navigate the control to it:
VB.NET:
Dim path As String = IO.Path.Combine(Application.StartupPath, "googlemap.html")
Me.WebBrowser1.Navigate(path)
It would look similar to this:
screen001.png

Another option is creating your own page with a map object and interacting with the Google Maps API through Javascript, once you have set up a page you can load it into WebBrowser control and interact with it from client application. The keys to this webpage-client interaction is the ObjectForScripting property where you can let JS access a COM object from your application, and HtmlElement.InvokeMember method where you can run JS functions in the page. (or HtmlDocument.InvokeScript)

I found an excellent example of doing this from this ComponentOne sample, Using C1Ribbon as an Interface to Google Maps, and took the liberty to write a VB.Net translation for educational purposes from the C# sample there. Check out the attached project, it is using the ComponentOne map, but ordinary .Net controls and not the nice control set they have. If they decide to move the map I've also included the source code for Html/JS in componentone.com.map.html file in zip package, you should examine this closely anyway to learn how it is done. It is not difficult to set up a map page like this on your own homepage. (you have to sign up for your own Google API key to use).

This is how my version of the app looks like:
GoogleMapsClient.png
 

Attachments

  • vbnet20-GoogleMapsClient.zip
    23.6 KB · Views: 34
Re: Zoom

Also an image on form having zoomin and zoomout buttons.
Please Help!!!!
:confused:
 
For example use a Picturebox in a Panel, control zoom with a Trackbar. These are the configurations I would use:
Picturebox: Sizemode=StretchImage
Panel: AutoScroll=True, Borderstyle=FixedSingle
Trackbar: Value=100, Maximum=200, Minimum=100
Then simply use Scroll event of Trackbar to calculate and set the zoom size of Picturebox:
VB.NET:
Dim factor As Single = Me.TrackBar1.Value / 100
Dim s As Size = Me.Panel1.ClientSize
s.Height *= factor
s.Width *= factor
Me.PictureBox1.Size = s
 
Back
Top