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;
}