Creating functions that give me latitude and longitude

WN1994

New Member
Joined
Feb 3, 2016
Messages
4
Hi, last week I ask for help to write a code that gives me latitude and longitude. I receipt this code which create some functions:

Code:
Function lat(a_t As String, c_t As String, s_t As String, co_t As String, z_t As String)
Dim sURL As String
Dim BodyTxt As String
Dim apan As String, la_t As String, lo_g As String
Dim oXH As Object
    'create web url
    sURL = "http://maps.googleapis.com/maps/api/geocode/xml?address="
    sURL = sURL & Replace(a_t, " ", "+") & ",+" & Replace(c_t, " ", "+") & ",+" & Replace(s_t, " ", "+") & _
                ",+" & Replace(co_t, " ", "+") & ",+" & ",+" & Replace(z_t, " ", "+") & ",+" & _
                "&sensor=false"
    ' browse url
    Set oXH = CreateObject("msxml2.xmlhttp")
            With oXH
              .Open "get", sURL, False
              .Send
              BodyTxt = .RESPONSETEXT
            End With
    apan = Application.WorksheetFunction.Trim(BodyTxt)
    'Latitude
    apan = Right(apan, Len(apan) - InStr(1, apan, "<lat>") - 4)
    la_t = Left(apan, InStr(1, apan, "</lat>") - 1)
lat = la_t
End Function


Function lon(a_t As String, c_t As String, s_t As String, co_t As String, z_t As String)
Dim sURL As String
Dim BodyTxt As String
Dim apan As String, la_t As String, lo_g As String
Dim oXH As Object
    'create web url
    sURL = "http://maps.googleapis.com/maps/api/geocode/xml?address="
    sURL = sURL & Replace(a_t, " ", "+") & ",+" & Replace(c_t, " ", "+") & ",+" & Replace(s_t, " ", "+") & _
                ",+" & Replace(co_t, " ", "+") & ",+" & ",+" & Replace(z_t, " ", "+") & ",+" & _
                "&sensor=false"
    ' browse url
    Set oXH = CreateObject("msxml2.xmlhttp")
            With oXH
              .Open "get", sURL, False
              .Send
              BodyTxt = .RESPONSETEXT
            End With
    apan = Application.WorksheetFunction.Trim(BodyTxt)
    'Longitude
    apan = Right(apan, Len(apan) - InStr(1, apan, "<lng>") - 4)
    lo_g = Left(apan, InStr(1, apan, "</lng>") - 1)
    lon = lo_g
End Function
At first time it works but now it doesn't anymore. I would like some help to know that happened. And other think I want is to correct this code so the functions have only one argument and no five like this: lon(a_t As String, c_t As String, s_t As String, co_t As String, z_t As String)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top