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.getElementB yId("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?
var map = new GMap2(document.getElementB
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(
}
}
);
}
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?
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?"
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?
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
ASKER