Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:30:53+00:00 2026-05-31T18:30:53+00:00

So I’m trying to retrieve the latitude and longitude of a given postal code,

  • 0

So I’m trying to retrieve the latitude and longitude of a given postal code, and am trying to use VBA to place this into an excel worksheet. My code is as follows:

Private appIE As Object

Function GeoCode(sLocationData As String) As String
'//Dont want to open and close all day long - make once use many
If appIE Is Nothing Then
    CreateIEApp
    '// Creates a new IE App
    '// if = nothing now then there was an error
    If appIE Is Nothing Then
        GeoCode = "Sorry could not launch IE"
        Exit Function
    Else
        '// do nothing
    End If
Else
    '// do nothing
End If
'//clearing up input data
'sLocationData = Replace(sLocationData, ",", " ")
sLocationData = Replace(sLocationData, " ", "+")
sLocationData = Trim(sLocationData)

'//Build URL for Query
sLocationData = "http://maps.google.com/maps/geo?q=%20_" & sLocationData

'// go to the google web service and get the raw CSV data
'// CAUSES PROBLEM AS SPECIFIED BELOW
appIE.Navigate sLocationData

Do While appIE.Busy
    Application.StatusBar = "Contacting Google Maps API..."
Loop

Application.StatusBar = False
On Error Resume Next

'// Parsing
GeoCode = appIE.Document.Body.innerHTML
GeoCode = Mid(GeoCode, InStr(GeoCode, ",") + 1, InStr(GeoCode, "/") - InStr(GeoCode, ",") - 2)

appIE = Nothing
End Function

The Google Maps API then returns a JSON formatted value, as per this link:

http://maps.google.com/maps/geo?q=%20_400012

I then attempt to retrieve this value using
appIE.Document.Body.innerHTML,
and parsing that value for the data I want. However, the moment the code hits appIE.Navigate sLocationData,
I’m prompted to save a file called “geo”. When saved and opened as a .txt file, I get the exact same JSON formatted value, but I need the values within my worksheet itself.

Is there a way to do this?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:30:54+00:00Added an answer on May 31, 2026 at 6:30 pm

    That link didn’t work for me in Firefox – response 610. If I remove the space and the underscore, it works. I don’t know why IE wants to download, probably some setting that tells it to always download JSON rather than render it. In any case, consider using MSXML’s http request rather than automating IE.

    Set a reference to Microsoft XML, v6.0 or similar (VBE – Tools – References).

    Function GeoCode(sLocData As String) As String
    
        Dim xHttp As MSXML2.XMLHTTP
        Dim sResponse As String
        Dim lStart As Long, lEnd As Long
    
        Const sURL As String = "http://maps.google.com/maps/geo?q="
        Const sCOOR As String = "coordinates"": " 'substring that we'll look for later
    
        'send the http request
        Set xHttp = New MSXML2.XMLHTTP
        xHttp.Open "GET", sURL & sLocData
        xHttp.send
    
        'wait until it's done
        Do
            DoEvents
        Loop Until xHttp.readyState = 4
    
        'get the returned data
        sResponse = xHttp.responseText
    
        'find the starting and ending points of the substring
        lStart = InStr(1, sResponse, sCOOR)
        lEnd = InStr(lStart, sResponse, "]")
    
        GeoCode = Mid$(sResponse, lStart + Len(sCOOR), lEnd - lStart - Len(sCOOR) + 1)
    
    End Function
    
    Sub Test()
    
        Dim sTest As String
    
        sTest = GeoCode("400012")
    
        Debug.Assert sTest = "[ 103.9041520, 1.3222160, 0 ]"
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.