Click here to Skip to main content
15,884,537 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Integrate G-MAP in VB.NET Windows Application without API

Rate me:
Please Sign up or sign in to vote.
4.50/5 (4 votes)
13 Nov 2014CPOL1 min read 17.4K   8  
How to Integrate Google map in VB.NET without using any API in VB.NET Windows application

Introduction

WebBrowser ActiveX documents are embeddable OLE objects that behave more like ActiveX controls than traditional OLE objects. Unlike a traditional embedded object, an ActiveX document is not designed to be a contained object in a larger document. Instead, it is considered in itself a complete document that is merely being viewed (such as with Microsoft Internet Explorer) or collected in a single resource with other documents (such as a Microsoft Office Binder file). An ActiveX document that is hosted in the WebBrowser control is always active; therefore, unlike traditional OLE embedded objects, there is no sense of in-place activation.
For getting direction using source and destinations in Google map, we have to use following URL:

https://www.google.com/maps/dir/

  • google map identifies space as + e.g. :acb xyz replace space with + e.g. :abc+xyz
  • and next line with comma e.g. abc+xyz,czy.
  • To make difference between source and destination, separate by ‘/’. Then use string builder to append the URL to web browser control. Each and every thing is explained in code. Code declaration of string builder and other things.
VB.NET
Dim queryaddress As New System.Text.StringBuilder 
Dim sStreet As String = String.Empty 
Dim sCity As String = String.Empty 
Dim sState As String = String.Empty 
Dim sPincode As String = String.Empty 
Dim sProvider_no As String = String.Empty 

queryaddress.Append("https://www.google.com/maps/dir/") 

Append source address to string builder

VB.NET
If txtprovider_no.Text <> ""
Then sProvider_no = txtprovider_no.Text.Replace(" ", "+") 
queryaddress.Append(sProvider_no + "," & "+")
End If
If txtState.Text <> ""
Then sState = txtState.Text.Replace(" ", "+") 
queryaddress.Append(sState + "," & "+")
End If
If txtCity.Text <> ""
Then sCity = txtCity.Text.Replace(" ", "+") 
queryaddress.Append(sCity + "," & "+")
End If

Append / for destination

queryaddress.Append("/")

Append destination address to string builder

VB.NET
sStreet = String.Empty
sCity = String.Empty
sState = String.Empty
sPincode = String.Empty

If ttxtclient_city.Text <> "" 
Then sPincode = ttxtclient_city.Text.Replace(" ", "+")
 queryaddress.Append(sPincode)
End If
If txtclient_state.Text <> "" 
Then sState = txtclient_state.Text.Replace(" ", "+") 
queryaddress.Append(sState + "," & "+")
End If

Last append URL to web browser control

VB.NET
WebBrowser.Navigate(queryaddress.ToString()) 

License

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


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This is a Social Group (No members)


Comments and Discussions

 
-- There are no messages in this forum --