Finding Coordinates of a Location

Greg_

New Member
Joined
Dec 16, 2015
Messages
20
Hello,

I am trying to fine-tune some code that I found that gets coordinates online and puts them into excel. The problem I'm having is that it doesn't always work 100% of the time for my purposes. Sometimes the location I am trying to get the coordinates for is for example Melbourne, Australia. It doesn't recognize the location as somewhere it can pull coordinates for. Any suggestions? Below is the code for the module. Thank you.

Code:
Function GoogleGeocode(address As String) As StringDim strAddress As String
Dim strQuery As String
Dim strLatitude As String
Dim strLongitude As String


strAddress = URLEncode(address)


'Assemble the query string
strQuery = "http://maps.googleapis.com/maps/api/geocode/xml?"
strQuery = strQuery & "address=" & strAddress
strQuery = strQuery & "&sensor=false"


'define XML and HTTP components
Dim googleResult As New MSXML2.DOMDocument
Dim googleService As New MSXML2.XMLHTTP
Dim oNodes As MSXML2.IXMLDOMNodeList
Dim oNode As MSXML2.IXMLDOMNode


'create HTTP request to query URL - make sure to have
'that last "False" there for synchronous operation


googleService.Open "GET", strQuery, False
googleService.send
googleResult.LoadXML (googleService.responseText)


Set oNodes = googleResult.getElementsByTagName("geometry")


If oNodes.Length = 1 Then
For Each oNode In oNodes
  strLatitude = oNode.ChildNodes(0).ChildNodes(0).Text
  strLongitude = oNode.ChildNodes(0).ChildNodes(1).Text
  GoogleGeocode = strLatitude & "," & strLongitude
 Next oNode
 Else
 GoogleGeocode = "Not Found (try again, you may have done too many too fast)"
 End If
 End Function
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

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