[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB6 - Query latitude and longitude with Google map issue

Posted on 2013-06-25
6
Medium Priority
?
1,738 Views
Last Modified: 2013-06-26
Hello all,

I have a function inside my VB6 app that will look at the address / city / state and postal code and then, use Google map to get the latitude and longitude.

When i'm home, it work great but when i"m log on a server, it does not work at all.

Would you know what it it?

How can i make it work at home and on the server also?

Thanks again for your help.

Module:
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Const IF_NO_CACHE_WRITE = &H4000000
Private Const BUFFER_LEN = 8192

Public Function GetUrlSource(sURL As String) As String
 Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String
 Dim hInternet As Long, hSession As Long, lReturn As Long
'=================================================
'get the handle of the current internet connection
'=================================================
 hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
'=========================
'get the handle of the url
'=========================
 If hSession Then
  hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0)
 End If
'=================
'READ WEB RESPONSE
'=================
 If hInternet Then
 '=====================================
 'GET FIRST CHUNK OF DATA AND BUFFER IT
 '=====================================
  iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
  sData = sBuffer
 '==============================================
 'LOOP THROUGH THE BALANCE AND ADD TO THE BUFFER
 '==============================================
  Do While lReturn <> 0
   iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
   sData = sData + Mid(sBuffer, 1, lReturn)
  Loop
 End If
'==========================================
'CLOSE THE CONNECTION AND RETURN THE RESULT
'==========================================
 iResult = InternetCloseHandle(hInternet)
 GetUrlSource = sData
End Function

Open in new window



AskGoogleButton:
 Latitude(1) = "": Latitude(2) = ""
 Longitude(1) = "": Longitude(2) = ""
 DoEvents
'==========================================
'CHECK IF USER FILLED IN THE ADDRESS FIELDS
'==========================================
 If MissingData Then
  MsgBox "Please fill in the form correctly.", vbApplicationModal + vbExclamation, "Whoops!"
  Exit Sub
 End If
 AskGoogleButton.Enabled = False
 Screen.MousePointer = 11
 Dim NotFound As Boolean
 For i = 1 To 2
  NotFound = True
  WebURL$ = "http://maps.google.com/maps?q="
  WebURL$ = WebURL$ & Trim$(Street(i)) & ",+"
  WebURL$ = WebURL$ & Trim$(City(i)) & ",+"
  WebURL$ = WebURL$ & Trim$(State(i)) & ",+"
  WebURL$ = WebURL$ & Trim$(Zip(i))
  WebURL$ = Replace$(WebURL$, " ", "+")
  GoogleWebPage$ = GetUrlSource(WebURL$)
  A$ = LCase$(GoogleWebPage$)
 '=======================================================
 'EXTRACT THE LATITUDE AND LONGITUDE FROM GOOGLE WEB PAGE
 '=======================================================
  GC = InStr(A$, ":{lat:") + 2
  If GC > 2 Then
   GC2 = InStr(GC, A$, "},")
   LC = GC2 - GC
   If LC > 20 And LC < 200 Then
    A$ = Mid$(A$, GC + 4, LC - 6)
    Comma = InStr(A$, ",")
    If Comma Then
     Lat$ = Left$(A$, Comma - 1) & String$(12, 48)
     Lat$ = Left$(Lat$, 12)
     Lon$ = Right$(A$, Len(A$) - (Comma + 4)) & String$(12, 48)
     Lon$ = Left$(Lon$, 12)
     If Abs(Val(Lat$)) > 0 And Abs(Val(Lon$)) > 0 Then
      Latitude(i) = Lat$
      Longitude(i) = Lon$
      NotFound = False
     End If
    End If
   End If
  End If
  DoEvents
 Next i
ReturnResult:
 Screen.MousePointer = Default
 If NotFound Then
  MsgBox "NO MAP COORDINATES HAVE BEEN FOUND!", vbApplicationModal + vbExclamation, "ADDRESS???"
  Beep
 Else ' Watch for my next upgrade - ok? (Dinner's waiting)
 '============================================================================
 'Why not put some MORE FUN into this and calculate the distance between them?
 '============================================================================
 End If
 AskGoogleButton.Enabled = True
 Exit Sub
BolloxedData:
 NotFound = True
 Resume ReturnResult:

Open in new window

0
Comment
Question by:Wilder1626
  • 4
6 Comments
 
LVL 7

Assisted Solution

by:dec0mpile
dec0mpile earned 200 total points
ID: 39274588
What is the error you are getting?

Many servers have security that prevents you from browsing the internet, so your script may be getting blocked by the server security from accessing the google maps site. Investigate the server firewall and internet access.

Which version of Windows server are you running this script on?

In later versions of Windows Sever the User Account Control prevents VBS scripts from performing many functions. Try to right click on the script and select "Run As Administrator" or disable UAC to rule out this possibility.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39274660
If i go manually on the web, i'm able to go on Google map.

It is only when i use the VB6 app.

what i have as a result is NO MAP COORDINATES HAVE BEEN FOUND! but this is because i don't link to the server i guess.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39276498
do you know another way that it would work?
Since i can go manually in Google map, i should be able to do the same thing from my app. Right?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 15

Accepted Solution

by:
eemit earned 1800 total points
ID: 39277310
Try this:

' Use registry access settings.
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0  'Retrieves the proxy or direct configuration from the registry.

Open in new window


Change (in Function GetUrlSource):
hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)

Open in new window

To:
hSession = InternetOpen("vb wininet", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39277994
Oh, i think it works now.

Let me do some validation and i will let you know.

Thanks.
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39279894
Hi again

It is now working great

Thanks again for your help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question