views:

53

answers:

1

Hi, I am trying to fetch the LatLon data from a request to Google. The Request.JSONP request works fine and returns the data perfect, but at the onSucces it returns a 'Invalid label' error.

Here is my script:

var G = {}

var googleURL = 'http://maps.googleapis.com/maps/api/geocode/json?address=';

G.google = function(id){
    var address = '500-504 W 20th St, New York, NY 10011, USA';
    var thisUrl = googleURL + address + '&sensor=true';

    new Request.google(thisUrl, {
        onSuccess: function(data) {
            console.log(data);
        }
    }).send();
}


Request.google = new Class({
    Extends: Request.JSONP,
    options: {},
    initialize: function(thisUrl, options) {
        this.parent(options);
        this.options.url = thisUrl;
    },
    success: function(data, script) {
        this.parent(data, script);
    }
});

The response looks like:

{
  "status": "OK",
  "results": [ {
    "types": [ "street_address" ],

But then Firebug reports a 'invalid label' error at '"status": "OK",\n'

Anyone got an idea how to solve this problem?

Many thanks.

+1  A: 

The reason is, googlemaps API has now stopped serving JSONP and returns plain JSON (from what I gather).

What mootools does is, send callback=Request.JSONP.request_map.request_0 to which the server should reply as:

Request.JSONP.request_map.request_0({
    "Status": "OK"
...
});

... that is, if callback= was not being ignored. Since it ignores it, the response is evaluated and 'run' as a simple JSON instead, producing an invalid label exception.

anyway, I recommend you read http://stackoverflow.com/questions/2921745/how-to-make-cross-domain-ajax-calls-to-google-maps-api - seems that their js soltution is completely viable here (aside from the extra script overhead)

Dimitar Christoff