Metrostop Back Up
January 10th, 2006
Fixing things was actually really easy. JSON is really nice.
On the server I had to update the regular expression to extract the JSON. I’m actually thinking about reworking this further to support the back button. I’ll load the google data into an iframe. Adding a function to the parent window that the iframe calls. This way onunload I can control the unwind and onload the forward is already encoded.
For now regex:
header('Content-Type: text/javascript');
$address = strip_tags($_GET["address"]);
$q = urlencode( $address );
$query = 'http://maps.google.com/maps?q=' . $q . '&output=js';
$json = trim( file_get_contents( $query ) );
$json = preg_replace( "/.*html *.*CDATA\[/", "", $json );
$json = preg_replace( "/function onLoad\(\) {window.parent.loadVPage\(/", "", $json );
$json = preg_replace( "/,document.getElementById\(\"state\"\)\);}\/\/\]\]>.*/", "", $json );
echo $json;
and on the client:
var data = window.eval( "(" + txt + ")" );
var point = new GPoint( data.overlays.markers[0].lng, data.overlays.markers[0].lat );

Recent Comments