Solved

VB6 - Query latitude and longitude with Google map issue

Posted on 2013-06-25
6
1,617 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 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 15

Accepted Solution

by:
eemit earned 450 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Hi again

It is now working great

Thanks again for your help
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now