By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,185 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,185 IT Pros & Developers. It's quick & easy.

Google Reverse Geocoding

P: 3
Hi,
I was creating an Application in MS Access for Geocoding a particular Address from Google to get the Lat & Long.
I successfully able to did that.
Here is the code:
****************************
On Error Resume Next 'if address not found, just move along

Dim xml_document As DOMDocument
Set xml_document = New DOMDocument
Dim rootNode As IXMLDOMNode
Set rootNode = xml_document.documentElement


Dim strURL1 As String
Dim objIE As Object
Dim IE As Object
Dim strSavePath As String
Dim URL As String, ext As String
Dim buf, ret As Long
Address = Text0.Value
city = Text2.Value
State = Text4.Value
Address = Replace(Address, " ", "+", 1)
zip = Text6.Value
sendstring = Address & ",+" & city & ",+" & State & ",+" & zip
If IsNull(Text6.Value) And IsNull(Text4.Value) Then
MsgBox "Please Provide State or Zip"
Exit Sub
Else
strURL = "http://maps.google.com/maps/geo?q=" & sendstring & "&output=xml&key=
'MsgBox strURL
'lat123.Value = strURL
Set objIE = Me.WebBrowser9.Object
objIE.Navigate strURL

Set XMLHTTP = CreateObject("Msxml2.XMLHTTP")

XMLHTTP.Open "GET", strURL, False
XMLHTTP.send

MyLat = XMLHTTP.responseXML.childNodes.length

xml_document.load XMLHTTP.responseXML

Set rootNode = xml_document.documentElement


Text30.Value = Left(rootNode.selectSingleNode("//coordinates").Text, InStr(rootNode.selectSingleNode("//coordinates").Text, ",") - 1)
Text28.Value = Mid(rootNode.selectSingleNode("//coordinates").Text, InStr(rootNode.selectSingleNode("//coordinates").Text, ",") + 1, InStr(rootNode.selectSingleNode("//coordinates").Text, ",") - 2)
End If
***************************************
Now what I want to do it, Is to do the reverse Geocoding. Like If I put the lat & Long in the Textbox in Ms Access Form, I should be able to get the Address for that lat or long. Or If I click anywhere on map. It should give me the lat & long in the textbox of that point.

I know the javascript function of that.
I got it from Google Reverse geocoding Reference guide.
Here is the code.

<html xmlns="http://www.w3.org/1999/xhtml">
<!--
Copyright 2007 Nico Goeminne (nicogoeminne@gmail.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
<title>GReverseGeocoder v1.0.4 Example</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA9K1YkDoSv7ab 5ZNpy7jKoRSNkqYZ2vhDE-J87_S4BEuTB46WEhTQ4bSutMETYeFCAGxideDhBPvI_w" type="text/javascript"></script>
<script src="http://nicogoeminne.googlepages.com/greversegeocoderv104.js" type="text/javascript"></script>
<script type="text/javascript">

// GMap2 object
var map;
// GReverseGeocoder object
var rg;
// text input fields
var lat;
var lng;
// result div
var info;

function load() {
if (GBrowserIsCompatible()) {
lat = document.getElementById("lat");
lng = document.getElementById("lng");
info = document.getElementById("info");

map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(51.05226693177032, 3.723893165588379), 15);
map.addControl(new GLargeMapControl());
rg = new GReverseGeocoder(map);

// add listners for the results
GEvent.addListener(rg, "load", goodresult);
GEvent.addListener(rg, "error", badresult);
// Clicking on the map fills in the lat and lng fields
// Just handy
GEvent.addListener(map, "click", handleClicks);
}
}

// is called with a placemark if the reverse geocode request was successfull
// sets the result div
function goodresult(placemark) {
var html = placemark.address + '<br />' + '<b>Country code:</b> ' + placemark.AddressDetails.Country.CountryNameCode;
info.innerHTML = html;
}

// is called if the reverse geocode request was unsuccessfull
function badresult() {
info.innerHTML = "Unable to reverse geocode";
}

// get the input form lat and lng fields and issue a reverse geocode
// request
function reverse(){
var point = new GLatLng(lat.value,lng.value);
rg.reverseGeocode(point);
}

// handy method to fill in the lat and lng fields by clicking on the map.
function handleClicks(marker, point){
lat.value=point.lat();
lng.value=point.lng();
}
</script>

</head>

<body onload="load()" onunload="GUnload()">
<p>Reverse Geocoding Example using the GReverseGeocder v1.0.4<br />
Copyright 2007, Nico Goeminne<br />
nicogoeminne at gmail.com</p>
<table>
<tr><td>Latitude (WGS84)</td><td><input id="lat" type="text" size="20" value="" /></td></tr>
<tr><td>Longitude (WGS84)</td><td><input id="lng" type="text" size="20" value="" /></td></tr>
<tr><td><input type="button" onclick="reverse()" value="Get Address"></td><td><div id="info"></div></td></tr>
<tr><td colspan="2"><div id="map" style="width: 400px; height: 400px;"></div></td></tr>
</table>
<!-- Google Analytics -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2430635-1";
urchinTracker();
</script>
</body></html>

****************************************
Now I want to translate this in Access VBA.
I wonder How to do that.
OR If anyone else has done the same thing in the past in VBA.
Or If u know a reverse geocoding app in MS Access.
I want to do that specially in Access.
Thank you for your Help.
Mar 21 '08 #1
Share this Question
Share on Google+
1 Reply


P: 1
Just send the Lat/Lon instead of the address.

ex.
<pre>http://maps.google.com/maps/geo?q=35.109149,-106.604076&output=xml&key=abcdefg</pre>

-Kirk
Jan 10 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.