We help IT Professionals succeed at work.

Want cache google geocodes

ncw
ncw asked
on
595 Views
Last Modified: 2013-12-13
I want return latitude and longitude geocodes from Google Maps api from an address string and cache these in a MySql table, co-ords will be used for loading a map at the location of the address. There are examples on the net for loading a Google map using an address, but this is without caching:

var map = new GMap2(document.getElementById("map"));
var geocoder = new GClientGeocoder();

function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
      }
    }
  );
}

I've also seen where a request can be sent with a url server side and it returns xml. Maybe that would work best for me using php, but I would have to parse the xml. All I want is 2 values, latitude and longitude so I can store these in a database table which would act as a cache. I would retrieve these values from the database for the same search to save time and number of calls to the Google server.

What format does the 'point' returned from getLatLng take? Can that be saved as is?

Any ideas please?
Comment
Watch Question

ncw

Author

Commented:
Just tested returning 'point' and I see it is in the format of eg (50.123456,-1.123456), but this is returned clientside in javascript so there's no way of inserting in the database. I need something similar serverside without having to parse xml unless there's an easy way to do the parsing.
ncw

Author

Commented:
Information at http://www.geospatialtraining.com/Newsletter/Summer%202006/Google%20Geocoding.htm indicates that the serverside request takes the form:
http://maps.google.com/maps/geo?q=<address>&output  =xml&key=<key>

So maybe my question should be "what's the easiest way to parse the returned xml and retrieve latitude and longitude?"

Commented:
cant you just make an AJAX request to a server side code that inserts it into a database?
ncw

Author

Commented:
I'm not familiar with AJAX, I didn't realise you could connect to the database from the client browser in that way.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
ncw

Author

Commented:
For anyone reading this I didn't try B_Dorsey's solution (it looks like it might be asp), I got my solution to work in the end.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.