Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor gurmukh's Avatar
    Join Date
    Feb 2009
    Posts
    54
    Hi Guys

    I am developing a service that reports the GPS co-ordinates of the device. However, there are times when the device reports location is found, but then the values of latitude and longitude are "undefined". Looking at the docs:

    [criteria.Updateoptions.PartialUpdates] Specifies whether longitude, latitude, and altitude information is always guaranteed. http://library.forum.nokia.com/index...1C4378307.html

    This is set to false, so I assume I would ALWAYS get a value? Here is a code snippet



    function getLocationAsync() {

    // Show notification status
    uiManager.showNotification(-1, "wait", "Trying to get GPS fix...", 0.1);

    // Disable partial updates so result returned is accurate GPS location.
    var updateoptions = new Object();
    updateoptions.PartialUpdates = false;
    updateoptions.UpdateTimeOut = 60000000;
    criteria.Updateoptions = updateoptions;


    try {
    // Create service object
    so = device.getServiceObject("Service.Location", "ILocation");

    // Create asynchronous method to call "callbackLocation" once GPS co-ordinates are known.
    so.ILocation.GetLocation(criteria,callbackLocation);

    } catch (e) {
    uiManager.showNotification(-1, "wait", "getLocationAsync: " + e, 0.1);
    }
    }

    function callbackLocation(transId, eventCode, result){

    // Update global variable gotLocation and cancel asynchronous method.
    if (gotLocation == false) {
    gotLocation = true;
    latitude = result.ReturnValue.Latitude;
    longitude = result.ReturnValue.Longitude;
    criteria.CancelRequestType="GetLocCancel";
    result = so.ILocation.CancelNotification(criteria);
    alert(longitude+latitude); // returns undefinedundefined
    }
    // Notify user GPS co-ordinates are found.
    uiManager.showNotification(-1, "wait", "Got it!", 0.3);

    // Get updated JSON object
    getJson();
    }

    Any advice would be great!

  2. #2
    Registered User jzferreira's Avatar
    Join Date
    Sep 2008
    Location
    Manaus, Brazil
    Posts
    109
    Ok. I don't understand what is the problem, but follow a code which works for me:

    Code:
    var test = test || {};
    
    /**
     * TODO
     */
    test.location = {
        _so: null,
        init: function(){
            try {
                this._so = device.getServiceObject("Service.Location", "ILocation");
            } 
            catch (e) {
            
            }
        },
        getLocation: function(callbackSuccess, callbackError){
        
            try {
                var updateoptions = {};
                
                updateoptions.PartialUpdates = false;
                
                var criteria = {};
                criteria.LocationInformationClass = "GenericLocationInfo";
                criteria.Updateoptions = updateoptions;
                
                var result = this._so.ILocation.Trace(criteria, function(transId, eventCode, result){
                
                    if (result.ErrorCode && result.ErrorCode !== 0) {
                        //ERROR
                        response = {
                            'error': result.ErrorMessage,
                            'code': result.ErrorCode
                        };
                        
                        callbackError.call(this, response);
                        
                    }
                    else {
                        //SUCCESS			
                        response = {
                            'success': 'Success Location',
                            'code': result.ErrorCode,
                            'longitude': result.ReturnValue.Longitude,
                            'latitude': result.ReturnValue.Latitude
                        };
                        
                        callbackSuccess.call(this, response);
                    }
                    
                });
                
                var errCode = result.ErrorCode;
                
                var response = null;
                
                if (errCode && errCode != 0) {
                
                    response = {
                        'error': result.ErrorMessage,
                        'code': result.ErrorCode
                    };
                    callbackError.call(this, response);
                }
            } 
            catch (e) {
            
            }
            
        }
    };
    Javier Zambrano Ferreira

  3. #3
    Regular Contributor gurmukh's Avatar
    Join Date
    Feb 2009
    Posts
    54
    Thanks Javier

    The difference I see with your code is that you are using the Trace approach and also are not cancelling the request once the initial co-ordinates are found.

  4. #4
    Registered User LWCARAB's Avatar
    Join Date
    Sep 2009
    Posts
    4
    Hello,

    I'm totally new to widget development and JavaScript to but I'm basically tring to play around with stuff and get my gps to return something, I've tried using your code and added some print lines but I don't get anything... any advice?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Sample Widget</title>
    		    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <link href="basic.css" rel="stylesheet" type="text/css" />
            
            <meta name="generator" content="Nokia WRT extension for Visual Studio 2.0" />
        </head>
        <body >
            <script type="text/javascript">
            var test = test || {};
    
            /**
            * TODO
            */
            test.location = {
                _so: null,
                init: function() {
                    try {
                        this._so = device.getServiceObject("Service.Location", "ILocation");
                    }
                    catch (e) {
    
                    }
                },
                getLocation: function(callbackSuccess, callbackError) {
    
                    try {
                        var updateoptions = {};
    
                        updateoptions.PartialUpdates = false;
    
                        var criteria = {};
                        criteria.LocationInformationClass = "GenericLocationInfo";
                        criteria.Updateoptions = updateoptions;
    
                        var result = this._so.ILocation.Trace(criteria, function(transId, eventCode, result) {
                            document.write(result.ErrorCode);
    
                            if (result.ErrorCode && result.ErrorCode !== 0) {
                                //ERROR
                                response = {
                                    'error': result.ErrorMessage,
                                    'code': result.ErrorCode
                                };
    
                                callbackError.call(this, response);
    
                            }
                            else {
                                //SUCCESS			
                                response = {
                                    'success': 'Success Location',
                                    'code': result.ErrorCode,
                                    'longitude': result.ReturnValue.Longitude,
                                    'latitude': result.ReturnValue.Latitude
                                };
    
                                callbackSuccess.call(this, response);
                                document.write(response);
                            }
    
                        });
    
                        var errCode = result.ErrorCode;
    
                        var response = null;
    
                        if (errCode && errCode != 0) {
    
                            response = {
                                'error': result.ErrorMessage,
                                'code': result.ErrorCode
                            };
                            callbackError.call(this, response);
                        }
                    }
                    catch (e) {
    
                    }
    
                }
            };
            </script>
    	</body>
    </html>

  5. #5
    Nokia Developer Moderator isalento's Avatar
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833
    Hello,

    gurmukh:
    Always check the result.ErrorCode before using the location data in the callback. You will probably get some error code, when undefined is returned.

    LWCARAB:
    You should init the code somehow. Like:

    Code:
    test.location.init();
    test.location.getLocation(
      function(response){ alert(response.success); }, 
      function(response){ alert(response.error); }
    );

    Br,
    Ilkka

  6. #6
    Regular Contributor gurmukh's Avatar
    Join Date
    Feb 2009
    Posts
    54
    Hi there

    I managed to fix it by just re-calling the function to get the Location if it was "undefined". That seems to do the trick.

    Changing the cache value, the timeout value etc made no difference.

    I also noticed that the JS was causing the browser to crash under certain situations so had to re-jig the whole thing.

    Trial and error :-)!

Similar Threads

  1. Replies: 1
    Last Post: 2009-10-12, 11:22
  2. Head Set Status
    By arunmdevan in forum Symbian C++
    Replies: 15
    Last Post: 2009-02-28, 04:30
  3. [moved] HELP! Phone Debug (GCCE)
    By joseph.m in forum Symbian C++
    Replies: 18
    Last Post: 2008-07-14, 10:42
  4. illegal use of abstract class error...
    By kannabiran.krish in forum Symbian C++
    Replies: 7
    Last Post: 2007-08-17, 10:11
  5. file not found
    By praktikant in forum Symbian C++
    Replies: 16
    Last Post: 2007-05-09, 15:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved