Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Want cache google geocodes

Posted on 2007-10-06
8
Medium Priority
?
571 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?
0
Comment
Question by:ncw
  • 4
  • 2
6 Comments
 
LVL 1

Author Comment

by:ncw
ID: 20027746
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.
0
 
LVL 1

Author Comment

by:ncw
ID: 20027760
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?"
0
 
LVL 14

Expert Comment

by:B_Dorsey
ID: 20027999
cant you just make an AJAX request to a server side code that inserts it into a database?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:ncw
ID: 20028076
I'm not familiar with AJAX, I didn't realise you could connect to the database from the client browser in that way.
0
 
LVL 14

Accepted Solution

by:
B_Dorsey earned 2000 total points
ID: 20028116
var xmlhttp;
var xmlResults;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try{
 xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
 try{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }catch(E){
  xmlhttp=false;
 }
}
@else
 xmlhttp=false
@end @*/
if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
 try{
  xmlhttp = new XMLHttpRequest();
 }catch(e){
  xmlhttp=false;
 }
}
if(!xmlhttp && window.createRequest){
 try{
  xmlhttp = window.createRequest();
 }catch(e){
  xmlhttp=false;
 }
}
 xmlhttp.open('POST','/path/to/server/side/code.asp',false);
 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
 xmlhttp.send('googlevariables'); //This is where you create a string of variables to send to the server side code.
 xmlResults = xmlhttp.responseText;

Basically what is going on is that you send the returned google variables to a string like 'google='50.123456,-1.123456' then on your server side code you handle it like a normal request.form and insert it into the database.
0
 
LVL 1

Author Comment

by:ncw
ID: 23054495
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.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question