2

I use PhoneGap 1.5.0 Cordova for Android, I modified PhoneGap Android official test/example project and tested it on two different phones. I send Google geocoding requests but after a few iterations it just stops working. the same code was ok with PhoneGap 1.4.1

Can you please explain this? Did you already found a solution?

Here is the code:

Geocoder: function() {
    var serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json', geocode, geocodeCoords, geocodeAddress;

    geocode = function(req, cb) {
        $.extend(req, {
            sensor : true,
            region : 'it',
            language : 'it'
        });
        var qs = $.param(req);
        $.ajax({
            type: 'GET',
            url : serviceurl,
            data : qs,
            success : function(d) {
                cb(d.results, d.status);
            },
            error : function(xhr, status, e) {
                alert('geocode error: ' + status);
                console.log(e);
                cb([], status || 'http error');
            }
        });
    };

    geocodeCoords = function(coords, cb) {
        var req = {
            latlng : [coords.latitude, coords.longitude].join(',')
        };
        geocode(req, function(arr, s) {
            cb(arr, s);
        });
    };

    geocodeAddress = function(addr, cb) {
        var req = {
            address : addr
        };
        geocode(req, function(arr, s) {
            cb(arr, s);
        });
    };

    /*
     * 1: obj.coords => { latitude: 0, longitude: 0 } 2: obj.address =>
     * string
     */
    this.geocode = function(obj, cb) {
        if (obj && obj.coords) {
            geocodeCoords(obj.coords, cb);
        } else if (obj && obj.address) {
            geocodeAddress(obj.address, cb);
        } else {
            throw new Error('geocoder failure: nothing to geocode');
        }
    };

    return this;
}
ColinE
  • 68,894
  • 15
  • 164
  • 232
Alessandro Annini
  • 1,531
  • 2
  • 17
  • 32

2 Answers2

3

here the explaination and the fix: Override Android Backbutton behavior only works on the first page with PhoneGap (last post: link to google group post).

The problem is in the cordova scripts for androids, line 4831: change

channel.onNativeReady.subscribe(_self.boot);

with

channel.onNativeReady.subscribeOnce(_self.boot);
Community
  • 1
  • 1
D_Guidi
  • 698
  • 1
  • 5
  • 10
1

I can confirm the behavior, I've tested this thing also using other rest services, so the problem looks not related to maps api. The strange thing is that no error messages are shown in phonegap/android log. BTW I've switched to 1.4.1, 1.5.0 looks unusable for me right now :(

EDIT: I've created a small cordova project that shows the bug. http://dl.dropbox.com/u/2663849/AjaxBug.zip

With this example, I've cheched a bit better the changes from 1.4.1 to 1.5.0 inside the android manifest and now the problem happens only occasionally in my google nexus smartphone. When the error happens, I see a message in the "LogCat" console: something related with a network connection error (but the wi-fi signal is still present and strong)

EDIT2: Actually the message I see is 03-19 09:54:00.617: D/CordovaLog(2113): timeout

So the call is "timeoutted" after approximately 20 seconds, ignoring the $.ajax.timeout property (set to 30 seconds).

D_Guidi
  • 698
  • 1
  • 5
  • 10