?
Solved

VB6 - Query latitude and longitude with Google map issue

Posted on 2013-06-25
6
Medium Priority
?
1,692 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month8 days, 14 hours left to enroll

764 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