Link to home
Create AccountLog in
Avatar of ncw
ncw

asked on

Want cache google geocodes

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?
Avatar of ncw
ncw

ASKER

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.
Avatar of ncw

ASKER

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?"
cant you just make an AJAX request to a server side code that inserts it into a database?
Avatar of ncw

ASKER

I'm not familiar with AJAX, I didn't realise you could connect to the database from the client browser in that way.
ASKER CERTIFIED SOLUTION
Avatar of B_Dorsey
B_Dorsey

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ncw

ASKER

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.