[ 
https://issues.apache.org/jira/browse/CB-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13158956#comment-13158956
 ] 

Shazron Abdullah commented on CB-64:
------------------------------------

by: http://github.com/shazron (2011-10-05T23:46:21Z)

This is already fixed. If this is a regression, this needs to be verifiable to 
be fixed. Post some test code.

There's a reason why this is different from the built in navigator.geolocation 
- this is to work around the alert title. If it times out once in a while it is 
acceptable because of network conditions. 

by: http://github.com/shazron (2011-10-05T23:53:46Z)

I tested using this: 
https://raw.github.com/gist/1251540/8d99e40dc331e1018b3d36e3b27d5018c19697fd/phonegap_geotest.html

by: http://github.com/shazron (2011-10-05T23:55:07Z)

Create a new PhoneGap 1.1 project, run it to make sure you get the "PhoneGap is 
working" alert. Then replace the index.html with the contents of 
https://raw.github.com/gist/1251540/8d99e40dc331e1018b3d36e3b27d5018c19697fd/phonegap_geotest.html

by: http://github.com/magic-uyr (2011-10-13T10:12:35Z)

the problem is the actual code, IOS wont constantly try and get a better fix, 
instead it seems to stop after about 3 times and wont respond unless the phone 
is moved, especially when your not on wifi.

before the phonegap app appears, the plugin has already executed and tried to 
get a location 3 times, then phonegap pages show, then you call 
getCurrentLocation.   this in turn calls to the location.m file that is 
currently waiting for you to move beyond 2 metres  if you dont, javascript 
reaches it timeout and hence the reason.

timeout should be set as infinity as advised, maxage should ideally be set at 
zero and if on 3G  its best to try and get outside to activate the AGPS    this 
is gps that uses WIFI and CELL to help get a better result.

his is the modification to my code:


NSTimeInterval localAge = -[newLocation.timestamp timeIntervalSinceNow];
        howManyTries++;
    if (localAge > 5.0) {
        NSLog(@"Got an old location");
        return;
    }
    
    if (newLocation.horizontalAccuracy < 0){
        NSLog(@"invalid measurements");
        return;
    }
    NSLog(@"Tried %@ Times",[NSNumber numberWithInt:howManyTries]);
    // we are going to try 3 times, and always return whatever we have on the 
third attemp
    
    
    if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy 
> newLocation.horizontalAccuracy){
        self.bestEffortAtLocation = newLocation;
        
        // lets see if we have a better accuracy  I.E  WIFI or GPS rather than 
Cell Tower
        if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy){
            howManyTries = 0;
            NSLog(@"have got a better match");
            
            NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setLocation(%@);", 
[bestEffortAtLocation JSONRepresentation]];
            [super writeJavascript:jsCallback];
            
        } 
        else if ( howManyTries >= 3){
            NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setLocation(%@);", 
[bestEffortAtLocation JSONRepresentation]];
            howManyTries = 0;
            [super writeJavascript:jsCallback];

        }
        else 
        {
            NSLog(@"not met desired accuracy yet!");
            return;
        }
        
    }    
    else 
    {
        if( howManyTries >= 3 ) {
            NSLog(@"Have done 5 times so i am now returning content");
            NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setLocation(%@);", 
[bestEffortAtLocation JSONRepresentation]];
            howManyTries = 0;
            [super writeJavascript:jsCallback];
            
        }
    }

this is inside location.m and didupdatetolocation      this is only called once 
movement has been detected,  so set timeout to Infinity on getCurrentLocation   
  

not sure if this is right, or bad or good or what! i am a complete IOS  / 
object-c novice and is something  i have just done from testing etc and just 
playing to see what happens.

by: http://github.com/gregavola (2011-10-13T12:08:17Z)

Has this been confirmed at all by the PhoneGap team?

by: http://github.com/magic-uyr (2011-10-13T12:08:22Z)

In xcode click on the phonegap project and go into classes i think
From: gregavola
Sent: 13 October 2011 12:58
To: magic-uyr
Subject: Re: [phonegap-iphone] navigator.geolocation.getCurrentPosition
still timeouts (#304)
How can you edit the location.m file?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/phonegap/phonegap-iphone/issues/304#issuecomment-2393898

by: http://github.com/magic-uyr (2011-10-13T12:57:39Z)

nope not confirmed, the guy on the phonegap support asked me to post on here.   
 plus if you use google or a simular search facility it details that it will 
wait for significant changes by default to save battery life etc.   i have it 
working on mine so confirm or not, it seems to work in all situations,  wifi or 
not wifi,   not moving or moving   and i dont use any battery either as i am 
not calling getCurrentLocation every min because my timeout is so low :-)

by: http://github.com/gregavola (2011-10-13T13:06:42Z)

Awesome - I can't wait to try this. Can you outline what lines and where you 
added this in the Location.m file? 

by: http://github.com/gregavola (2011-10-13T14:42:22Z)

@magic-uyr can you tell us where you placed the code?

by: http://github.com/magic-uyr (2011-10-13T14:56:05Z)

phonegap > classes > commands > location.h

    /*

      * PhoneGap is available under *either* the terms of the modified BSD 
license *or* the

     * MIT License (2008). See http://opensource.org/licenses/alphabetical for 
full text.
 
     * 

     * Copyright (c) 2005-2010, Nitobi Software Inc.

       */





        #import 

        #import 

        #import "PGPlugin.h"



          enum HeadingStatus {

          HEADINGSTOPPED = 0,

          HEADINGSTARTING,

           HEADINGRUNNING,

           HEADINGERROR

             };

          t ypedef NSUInteger HeadingStatus;



            // simple object to keep track of heading information

             @interface PGHeadingData : NSObject {

              HeadingStatus     headingStatus;

              BOOL              headingRepeats;

               CLHeading*        headingInfo;

                  NSMutableArray*   headingCallbacks;

                 NSString*         headingFilter;

                 }



              @property (nonatomic, assign) HeadingStatus headingStatus;

             @property (nonatomic, assign) BOOL headingRepeats;

             @property (nonatomic, retain) CLHeading* headingInfo;

             @property (nonatomic, retain) NSMutableArray* headingCallbacks;

             @property (nonatomic, retain) NSString* headingFilter;



              @end



              @interface PGLocation : PGPlugin  {



                   @private BOOL              __locationStarted;

                 PGHeadingData*    headingData;

                  CLLocation *bestEffortAtLocation;

                 NSInteger howManyTries;

                  }



                @property (nonatomic, retain) CLLocationManager 
*locationManager;

                    @property (nonatomic, retain) PGHeadingData* headingData;

                  @property (nonatomic, retain) CLLocation 
*bestEffortAtLocation;



               - (BOOL) hasHeadingSupport;



              - (void)startLocation:(NSMutableArray*)arguments

                  withDict:(NSMutableDictionary*)options;



                 - (void)stopLocation:(NSMutableArray*)arguments

                     withDict:(NSMutableDictionary*)options;



                    - (void)locationManager:(CLLocationManager *)manager

               didUpdateToLocation:(CLLocation *)newLocation

           fromLocation:(CLLocation *)oldLocation;



           - (void)locationManager:(CLLocationManager *)manager

                     didFailWithError:(NSError *)error;



             - (BOOL) isLocationServicesEnabled;



                       - (void)getCurrentHeading:(NSMutableArray*)arguments 
withDict:(NSMutableDictionary*)options;

                        - (void)returnHeadingInfo: (NSString*) callbackId 
keepCallback: (BOOL) bRetain;



- (void)stopHeading:(NSMutableArray*)arguments

  withDict:(NSMutableDictionary*)options;

- (void) startHeadingWithFilter: (CLLocationDegrees) filter;

- (void)locationManager:(CLLocationManager *)manager

  didUpdateHeading:(CLHeading *)heading;



- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager 
*)manager;



                 @end



location.m

                  - (void) locationManager:(CLLocationManager *)manager

                 didUpdateToLocation:(CLLocation *)newLocation

                 fromLocation:(CLLocation *)oldLocation

                 {

    NSLog(@"got a new measurement, i think!");

    NSTimeInterval localAge = -[newLocation.timestamp timeIntervalSinceNow];

howManyTries++;

    if (localAge > 5.0)  return; 

    

    if (newLocation.horizontalAccuracy < 0) return; 

    

    if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy 
> newLocation.horizontalAccuracy){

        self.bestEffortAtLocation = newLocation;

        

        // lets see if we have a better accuracy  I.E  WIFI or GPS rather than 
Cell Tower

        if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy){

            howManyTries = 0;

                    

            NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setLocation(%@);", [newLocation 
JSONRepresentation]];

            [super writeJavascript:jsCallback];

            [self.locationManager stopUpdatingLocation];

            __locationStarted = NO;

            howManyTries = 0;

        } 

        else if ( howManyTries >= 3){

            NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setLocation(%@);", [newLocation 
JSONRepresentation]];

            howManyTries = 0;

            [super writeJavascript:jsCallback];

            [self.locationManager stopUpdatingLocation];

            __locationStarted = NO;

            howManyTries = 0;

        }

        else 

        {

            NSLog(@"not met desired accuracy yet!");

            return;

        }

        

    }    

    else 

    {

        if( howManyTries >= 3 ) {

            NSLog(@"Have done 5 times so i am now returning content");

            NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setLocation(%@);", [newLocation 
JSONRepresentation]];

            [super writeJavascript:jsCallback];

            [self.locationManager stopUpdatingLocation];

            __locationStarted = NO;

            howManyTries = 0;

            

        }

    }

    // catch any other return i may have missed

    return;

    

}



- (void) startLocation:(NSMutableArray*)arguments 
withDict:(NSMutableDictionary*)options

{

    NSLog(@"Have started to look for you!");

    howManyTries = 0;

    if (![self isLocationServicesEnabled])

{

BOOL forcePrompt = NO;

// if forcePrompt is true iPhone will still show the "Location Services not 
active." Settings | Cancel prompt.

if ([options objectForKey:kPGLocationForcePromptKey]) 

{

forcePrompt = [[options objectForKey:kPGLocationForcePromptKey] boolValue];

}

        

if (!forcePrompt)

{

            NSError* error = [NSError errorWithDomain:kPGLocationErrorDomain 
code:1 userInfo:

                              [NSDictionary dictionaryWithObject:@"Location 
services is not enabled" forKey:NSLocalizedDescriptionKey]];

            NSLog(@"%@", [error JSONRepresentation]);

            

NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setError(%@);", [error 
JSONRepresentation]]; 

[super writeJavascript:jsCallback];

            

return;

}

    }

    if (![self isAuthorized]) 

    {

        NSUInteger code = -1;

        BOOL authStatusAvailable = [CLLocationManager 
respondsToSelector:@selector(authorizationStatus)]; // iOS 4.2+

        if (authStatusAvailable) {

            code = [CLLocationManager authorizationStatus];

        }

        

        NSError* error = [NSError errorWithDomain:NSCocoaErrorDomain code:code 
userInfo:

                          [NSDictionary dictionaryWithObject:@"App is not 
authorized for Location Services" forKey:NSLocalizedDescriptionKey]];

        NSLog(@"%@", [error JSONRepresentation]);



        NSString* jsCallback = [NSString 
stringWithFormat:@"navigator.geolocation.setError(%@);", [error 
JSONRepresentation]];

        [super writeJavascript:jsCallback];

        

        return;

    }


    // Tell the location manager to start notifying us of location updates

    self.locationManager.distanceFilter = kCLDistanceFilterNone;

    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [self.locationManager startUpdatingLocation];

    __locationStarted = YES;

    

    

    CLLocationAccuracy desiredAccuracy = kCLLocationAccuracyBest;

    

    if ([options objectForKey:kPGLocationDesiredAccuracyKey]) 

    {

        int desiredAccuracy_num = [(NSString *)[options 
objectForKey:kPGLocationDesiredAccuracyKey] integerValue];

        

        

        if (desiredAccuracy_num < 10) {

            desiredAccuracy = kCLLocationAccuracyBest;

        }

        else if (desiredAccuracy_num < 100) {

            desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

        }

        else if (desiredAccuracy_num < 1000) {

            desiredAccuracy = kCLLocationAccuracyHundredMeters;

        }

        else if (desiredAccuracy_num < 3000) {

            desiredAccuracy = kCLLocationAccuracyKilometer;

        }

        else {

            desiredAccuracy = kCLLocationAccuracyBest;

        }

        

        NSLog(@"i have started looking for your location!");

        

        

        self.locationManager.desiredAccuracy = desiredAccuracy;

    }

}

@synthesize locationManager, headingData, bestEffortAtLocation;



javascript  phonegap.1.1.0.js



Geolocation.prototype.getCurrentPosition = function(successCallback, 
errorCallback, options) 

{

    // create an always valid local success callback

    if ( this.listener !== null ) return;

    Log('Geo Location getCurrentPosition has been called');

    var win = successCallback;

    if (!win || typeof(win) != 'function')  win = function(position) {};

    

    // create an always valid local error callback

    var fail = errorCallback;

    if (!fail || typeof(fail) != 'function') fail = function(positionError) {};



    var self = this;

    var totalTime = 0;

var timeoutTimerId;


// set params to our default values

var params = new PositionOptions();

params.maximumAge = 0;

params.enableHighAccuracy = true;

params.timeout = Infinity;

    

    this.listener = {"success":win,"fail":fail};

    this.start(params);


var onTimeout = function()

{

    self.setError( new PositionError( PositionError.TIMEOUT, "Geolocation 
Error: Timeout." ) );

};



    clearTimeout( this.timeoutTimerId );

    this.timeoutTimerId = setTimeout( onTimeout, Infinity ); 

};



my success code:

function GeoSuccess( position ) {

Log('Got geo results');

setTimeout( "GetGeoLocation();",2000000 );

//setTimeout( "GetGeoLocation();", 10000 );


Log('\n Latitude: '          + position.coords.latitude          + '\n' +

          'Longitude: '         + position.coords.longitude         + '\n' +

          'Altitude: '          + position.coords.altitude          + '\n' +

          'Accuracy: '          + position.coords.accuracy          + '\n' +

          'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +

          'Heading: '           + position.coords.heading           + '\n' +

          'Speed: '             + position.coords.speed             + '\n' +

          'Timestamp: '         + new Date(position.timestamp)      + '\n');

}



thats it,   you will have to get checks by phonegap   as i said i am object-c 
novice and have litrally been doing object-c for about 3 days since i started 
using the plugin and couldn't get any help.  if you do any useful changes then 
please let me know.



ta

by: http://github.com/gregavola (2011-10-13T19:25:03Z)

You should def fork this into the build or some mod should test if it works!

by: http://github.com/magic-uyr (2011-10-13T21:12:39Z)

probably will once i get done, under huge pressure to get finished :-|   

by: http://github.com/gregavola (2011-10-15T15:29:01Z)

Is there anything I can do to help here? I'm in despart need of help!

by: http://github.com/gregavola (2011-10-19T20:45:34Z)

Hey @magic-uyr - any luck here? Just wanted to reach out!

by: http://github.com/schmitti12345 (2011-10-25T05:39:19Z)

anything new?

by: http://github.com/gregavola (2011-10-25T14:32:40Z)

To my knowledge there is noting new for this issue. I've had to cache the 
location for the user on the first attempt and not have them request it again - 
but it just won't work unless they physically move their device.

I wish this bug would be patched soon.

by: http://github.com/schmitti12345 (2011-10-25T16:12:27Z)

i posted it here again: [#1](https://github.com/callback/callback-ios/issues/1)

by: http://github.com/gregavola (2011-10-25T16:25:02Z)

What is callback?

by: http://github.com/magic-uyr (2011-10-25T16:36:30Z)

You need to set your timeout to infinity and / or look for nearest
match and return best results. There is no bug as such, its just
phonegap dont do good or useful code, especially the geo plugin. Have a
look on the apple developer site examples. The example code there is
better than phonegaps effort and gives you an idea. Also geo works best
with wifi chip enabled, u dnt need to be connected, just enabled and
near hotspots for better and quicker results From: gregavola
Sent: 25 October 2011 17:25
To: magic-uyr
Subject: Re: [phonegap-iphone] navigator.geolocation.getCurrentPosition
still timeouts (#304)
What is callback?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/phonegap/phonegap-iphone/issues/304#issuecomment-2519340

by: http://github.com/gregavola (2011-10-25T16:44:51Z)

@magic-uyr It's defintely a bug - because it doesn't work out of the box. If 
you can fix it - you should do a pull request and plop the code in there so 
other devs can use it. I'm not an Obj-C guy - hence why I use PhoneGap. If you 
could outline your steps to put this into the current phonegap ap - that would 
be great. I saw your code- but I'm lost on where to put it on how to recompile.

by: http://github.com/magic-uyr (2011-10-25T17:24:47Z)

I dnt do phonegap anymore and i dnt do consultation you need to get a
phonegap support account if u need something more robust and done for
you. That is not directed to be rude in anyway, just sound advice From:
gregavola
Sent: 25 October 2011 17:44
To: magic-uyr
Subject: Re: [phonegap-iphone] navigator.geolocation.getCurrentPosition
still timeouts (#304)
@magic-uyr It's defintely a bug - because it doesn't work out of the
box. If you can fix it - you should do a pull request and plop the
code in there so other devs can use it. I'm not an Obj-C guy - hence
why I use PhoneGap. If you could outline your steps to put this into
the current phonegap ap - that would be great. I saw your code- but
I'm lost on where to put it on how to recompile.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/phonegap/phonegap-iphone/issues/304#issuecomment-2519595

by: http://github.com/schmitti12345 (2011-10-25T18:07:37Z)

PhoneGap is now Called Callback (because it was accepted as Apache Project):
https://github.com/callback/callback-ios

by: http://github.com/mydestination (2011-10-27T08:53:20Z)

Hi Shazron, I have used your geo test page with 1.1.0 and recreated the problem 
with logfiles etc... The problem is evident when you are connected to wifi, it 
times out. If I disable wifi then it works as expected (or go out of range).

Let me know if you want the logfiles, screen shots etc... I think for a lot of 
people this is still a big problem with Phonegap.

Thanks Mark

by: http://github.com/sromalewski (2011-10-30T22:49:22Z)

@Shazron, your code works ok... BUT your situation is calling watchPosition 
once and then never calling it again.  

But if you have a situation where watchPosition is called, the position is 
successfully obtained, then you clear the watchID because you don't want to 
waste the phone's battery, and then your app is configured so the user can 
manually call watchPosition again, then this second or otherwise subsequent 
time that watchPosition is called, it times out.  Neither the success nor the 
failure callbacks are ever called during these subsequent attempts.

As @gregavola has pointed out in 
https://github.com/callback/callback-ios/issues/1 , you need to cache your 
lat/lon from the first watchPosition, then hopefully either reuse this, or 
force watchPosition to be called again -- and hope for the best.

by: http://github.com/Lichterloh (2011-11-26T22:43:04Z)

Any news on this topic? I am facing the same issue with iOS 5.0.1 and Phonegap 
1.2.0.

Only solution till now is the usage of geolocation at the beginning, when the 
native api is not already started :-(

                
> navigator.geolocation.getCurrentPosition still timeouts
> -------------------------------------------------------
>
>                 Key: CB-64
>                 URL: https://issues.apache.org/jira/browse/CB-64
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: iOS
>            Reporter: Shazron Abdullah
>
> reported at: https://github.com/phonegap/phonegap-iphone/issues/304
> by: https://github.com/schmitti12345
> unfortunately the issues 
> https://github.com/phonegap/phonegap-iphone/issues/197
> and https://github.com/phonegap/phonegap-iphone/issues/283
> still exists in phonegap 1.1.0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to