#16 √ resolved
Hugo

navigator.geolocation does not make use of GPS data

Reported by Hugo | December 16th, 2009 @ 01:23 AM

On the iPhone, navigator.geolocation references the Safari Geolocation API, not the Geolocation() phonegap object. As a result, only Wifi & cell tower triangulation data are being used to pinpoint the location (and the accuray these signals falls short of the accuracy from GPS - especially outside or urban areas)

Steps to reproduce (...short of walking on the countryside to compare accuracy with Phonagap app Vs maps):
1. In the sample application, add the following line to index.html's getLocation() function:
debug.log(navigator.geolocation.watchPosition.toString());
2. Start the sample application, click the 'Get Location' button and check that you see this in the logs instead of the expected watchPosition() function defined in geolocation.js

function watchPosition() {

{mkd-extraction-a764e38f28403e5ce435038db0d592a7}

}

Re: http://groups.google.com/group/phonegap/browse_thread/thread/32da55...#

Comments and changes to this ticket

  • Shazron Abdullah

    Shazron Abdullah September 11th, 2009 @ 04:53 PM

    Unfortunately based on my tests, we cannot bind to "navigator.geolocation" to override UIWebView's default implementation in 3.0.


    If we want to enable PhoneGap geoloc, we will have to be bind to another property. The impact: addition of another API call, and Objective-C changes.



    Will need to discuss with the team about the impact.

  • Jesse

    Jesse December 16th, 2009 @ 01:23 AM

    • → Assigned user changed from “” to “Jesse”

    Okay, until we decide how to refactor this with the least impact, I will post the workaround.

    The js Geolocation object defined in phonegap.js functions correctly and was in use until the 3.0 update that added the same functionality to the navigator object, and overwrote the phonegap functionality. You will not need to modify phonegap.js.

    In your html/js code, create your own Geolocation object: ( define it in a global scope, so it can be accessed from Obj-C code.

    
    // in js
    var myLocation = new Geolocation();
    myLocation.getCurrentPosition(onLocSuccess);
    myLocation.start();
    
    
    // in Obj-C -  Location.m ( in the commands folder )
    // Replace the 2 calls to callback to javascript to use your js object :
    
    NSString * jsCallBack = [NSString stringWithFormat:@"myLocation.setLocation({ timestamp: %d, %@ });", epoch, coords];
    
    // and
    
    jsCallBack = [NSString stringWithFormat:@"myLocation.setError(\"%s\");",
                                     [error localizedDescription]
                                    ];
    

    Also: Note the case of Geolocation, I kept thinking it should be GeoLocation and hence stared blankly at my code for awhile when it didn't work.

  • Shazron Abdullah

    Shazron Abdullah December 24th, 2009 @ 03:30 PM

    Ok, the PhoneGap team discussed it and found out there is workaround for this. Although navigator.geolocation CANNOT be overridden, the properties of the navigator.geolocation object CAN be overridden.

    So the fix is to override all the navigator.geolocation API functions with our old geolocation functions.

    eg

        var myGeo = new Geolocation();
        navigator.geolocation.getCurrentPosition = function()
        {
             myGeo.getCurrentPosition.apply(myGeo,arguments);
        }
        navigator.geolocation.setLocation = function()
        {
            myGeo.setLocation.apply(myGeo,arguments);
        }
    
  • Jesse

    Jesse January 28th, 2010 @ 01:19 AM

    • → State changed from “new” to “resolved”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

All iphone related issues.

You can update this ticket by sending an email to from your email client. (help)