PDA

View Full Version : Solved: Using Google Maps for Longitude and Latitude



halldo67
11-03-2009, 12:51 PM
I am trying to use Access to calculate distance measurements from new addresses (Longitude/Latitude unknown) to existing adresses (Longitude/Latitude known). I woluld like to use google maps to feed the longitude and latitude for the new address. I found the following code that will open Internet explorer and locate the new address on the map.

Private Sub Command14_Click()
Dim MyHyperlink As String, strGoogleLocation As String
Dim ie As Object, strTadd As String
'Create Addresses to review
strGoogleLocation = Me![Address] & "+" & Me![City] & "+" & Me![State] & "+" & Me![Zip]

'Create Link to navigate to
MyHyperlink = "http:"
MyHyperlink = MyHyperlink & "//maps.google.com/maps?q=" & strGoogleLocation
'Open Internet and create Map
Set ie = CreateObject("InternetExplorer.application")
ie.navigate MyHyperlink
ie.Visible = True
End Sub


When the map is created It will create a pointer icon. If you right click on the pointer icon and select What's Here? from the menu, the latitude and longitude will apear in the search window. This is the data that I am after, can anyone help me with the VBA code necessary to capture the longitude and latitude into the database without any manual efforts. I am not tied to google maps, I am just trying to get longitude and latitude without it being looked up.

Thanks in advance for any insight you may be able to share.

Halldo67

the member formerly known as just halldo!

CreganTur
11-03-2009, 01:40 PM
There are books that speak directly to using the google maps API- that would have the information you need. What you're doing with your code is mimicing the parameters that are sent to the map when a user enters their demographic information. You're not actually interfacing with the map at all.

I have some code that can pull data out of some objects on web pages, but to make it work you have to know the name of the object, and if you don't know it up front, it involves a ton of guesswork using Vie->Source. Try it on a map that your code brings up. You're going to see an insane ammount of code. Plus there's no gaurantee that the VBA I have will force the object to expose its values.

halldo67
11-04-2009, 06:32 AM
CreganTur,
I have found the location of the Longitude and Latitude on a different site via the view source code. The actual values are hard coded into the results view, which I can grab via the code you reference. Any chance you can share the code to pull objects?

CreganTur
11-04-2009, 07:25 AM
Here you go- it's an old example that puts data into objects on a website, and then reads data from the objects in a messagebox.

Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")

ie.navigate "http://zip4.usps.com/zip4/welcome.jsp"
ie.Visible = True

While ie.busy
DoEvents
Wend
ie.Document.All("address2").Value = "123 Carraige Way"
ie.Document.All("city").Value = "Shreveport"
ie.Document.All("state").Value = "CA"
ie.Document.All("zip5").Value = "9021"

MsgBox "Object values are:" & vbCrLf & vbCrLf & ie.Document.All("address2").Value & vbCrLf _
& ie.Document.All("city").Value & vbCrLf & ie.Document.All("state").Value & vbCrLf _
& ie.Document.All("zip5").Value

HTH:thumb

halldo67
11-04-2009, 11:43 AM
This looks like what I need. I am going to work with this and see what I can figure out. Thank you for pointing me in the right direction.

halldo67
11-06-2009, 02:23 PM
Problem is resolved thanks for all your help.

bjjgq
11-09-2009, 02:17 AM
ok,to be usefull

marketingman
10-22-2012, 12:35 PM
halldo67 can you post your code that was resolved, i too am looking to parse the lat and long via the google map in my vb form.