Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

forwardGeocoder doesn't release connection

I'm using forwardGeocoder in my app and it works perfectly in the app, but for some reason once forwardGeocoder has been invoked, it seems to continue to use the internet connection. The connection spinner in the status bar continues to indicate activity, even though the forwardGeocoder action is complete.

This could be problematic since the app may continue to consume resources (or at least appear to) and incur unneeded data usage charges.

Does anyone know how I can force disconnection of the internet connection at the end of my forwardGeocoder function?

I'm using sdk 1.4.2-r8e6bd670 but this has been happening for a while now and I think I need to fix it before submitting the app.

— asked September 26th 2010 by Randy Hall
  • connection
  • forwardgeocoder
  • internet
  • iphone

1 Answer

  • Accepted Answer

    I too am having some network activity indicator continuous spinning problems recently. I have kind of wondered if it was just something missed in the newest continuous builds.

    Anyways, one day I was having tons of problems with Titanium's forward geocoder (like if I entered Cupertino like the Kitchen Sink example it worked, anywhere else it failed). So I got fed up and have simply started calling google directly. I have included some of my code if you care to give it a try. It might help your situation…..though you will likely want to reduce my setTimeout.

    //Get LAT & LON from user entered location
    function getGeoLocation(strLocation) {
        var lat = 0;
        var lon = 0;
        var location = '';
        if (!Titanium.Network.online) {
        } else {
            var xhrGeocode = Titanium.Network.createHTTPClient();
            xhrGeocode.onload = function (e) {
                var response = JSON.parse(this.responseText);
                if (response.status == 'OK' && response.results != undefined && response.results.length > 0) {
                    lat = response.results[0].geometry.location.lat;
                    lon = response.results[0].geometry.location.lng;
                    location = strLocation;
            xhrGeocode.onerror = function (e) {};
            var url = "http://maps.google.com/maps/api/geocode/json?address=" + strLocation.replace(' ', '+');
            url += "&sensor=" + (Titanium.Geolocation.locationServicesEnabled == true);
            xhrGeocode.open("GET", url);
            xhrGeocode.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
    — answered September 27th 2010 by Mike Robinson
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.