×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    6

    Question Unable to use Code Examples for Camera and GPS Positioning together

    Hi,
    Both the following examples work separately, but when I put them together, I get the error
    "ReferenceError: Can't find variable: com" for the following line:
    so = com.nokia.device.load("", "com.nokia.device.camera", "");

    The examples from the code examples section that I am trying to integrate into one:
    http://wiki.forum.nokia.com/index.ph..._in_WRT_Widget
    http://wiki.forum.nokia.com/index.ph...ition_with_WRT

    Are the two examples using different versions of platform services APIs? If so, can you please suggest a fix?

    Thanks a lot!
    Vidya Sagar.S
    http://s4sagar.co.cc

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Unable to use Code Examples for Camera and GPS Positioning together

    Hello,
    Camera example is written for ps 2.0 beta code you could the one below instead, and switch to PS 2.0 location api as well.

    Code:
    var camera_so;
    
    /**
     * Error Callback
     * @param {DeviceError} err
     */
    function camera_takePicture_error_callback(err){
        alert("Error Code:" + err.code + " Error Message:" + err.message);
    }
    
    /**
     * Success Callback
     * @param {Object} picture_array
     */
    function camera_takePicture_callback(picture_array){
    
        var list = "";
    	
        for (var i = 0; i < picture_array.length; i++) {
        
            list += "URI:" + picture_array[i].uri + "\n";
            
            var formatData = picture_array[i].format;
            list += "Mime: " + formatData.type + "\nWidth: " + formatData.width + "\nHeight: " + formatData.height;
        }
    	
        alert(list);
    }
    
    /**
     * Takes a picture with a native camera application
     */
    function camera_takePicture(){
    
        try {
    		//Remember to add Platform Services 2.0 lib into your project from "Import Add-on library" 
            camera_so = nokia.device.load("camera");
            
    		//launch native camera application and retreive the captured image
            var transactionID = camera_so.startCamera(camera_takePicture_callback, camera_takePicture_error_callback);
      
        }catch (e) {
            alert(e);
        }
    }

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    6

    Re: Unable to use Code Examples for Camera and GPS Positioning together

    Thanks a lot isalento! The camera code worked perfectly with the Location example.

    Quote Originally Posted by isalento View Post
    Camera example is written for ps 2.0 beta code you could the one below instead, and switch to PS 2.0 location api as well.
    Is the Location API example written for beta as well? Are you suggesting me to migrate that code to PS2.0 from PS2.0 Beta?
    If you do, can you also please link me to a code example as to how to use?

    Thanks again!
    -Vidya Sagar.S

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Unable to use Code Examples for Camera and GPS Positioning together

    The location API example is PS 1.0 style, which is just slightly harder to use compared to PS 2.0 location API. But as you already got PS 1.0 version working, there is no real need to switch to PS 2.0. Actually PS 2.0 platformservices.js only wraps the PS 1.0 API.

    Anyhow here is the PS 2.0 location API example if you want to test it out.
    Code:
    *
     * Geolocation service object based on com.nokia.device.geolocation Interface
     */
    var geolocation_so = null;
     
    /*
     * Initializes geolocation service object
     */
    function initGeolocation(){
    
        try {
    		geolocation_so = nokia.device.load("geolocation");
    	} 
    	catch (e) {
    		if (e.message == "security access check failed") {
    			alert("Access to location service was not granted");
    		}
    		else {
    			alert(e);
    		}
    	}
    }
    
    /**
     * Error Callback
     * @param {PositionError} result
     */
    function location_SingleShot_error_callback(result){
    	
        alert('Error retrieving position\ncode :' + result.code + '\nmessage: ' + result.message);
    }
    
    
    /**
     * Callback function that is called with positionInformation when
     * location is obtained successfully 
     * @param {Position} position
     */
    function location_SingleShot_callback(position){
        var latitude  = position.coords.latitude;
    	var longitude = position.coords.longitude;	
    	
    	alert("Lat: " + latitude + "\nLong: " + longitude );
    }
    
    
    /**
     * Retrieves the current geographic location of the device
     */
    function getLocationSingleShot(){
    
    	//see PositionOptions object
    	var positionOpts = {
    		enableHighAccuracy : false,
            timeout: 120000,   //GPS timeout in ms, 120000 (2min) is recommended
            maximumAge: 60000  //Enables the use of cached location. Must be less than timeout
            				   //Special values: 0 always new, Infinity to retrieve last known position.
        };
    	
        try {		
            geolocation_so.getCurrentPosition(location_SingleShot_callback, location_SingleShot_error_callback, positionOpts);
    		
        }catch (e) {
            var error = e.toString();
            alert(error);
        }
    }
    -Ilkka

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    6

    Re: Unable to use Code Examples for Camera and GPS Positioning together

    Thanks a lot Ilkka!

    Code:
           //see PositionOptions object
    	var positionOpts = {
    		enableHighAccuracy : false,
            timeout: 120000,   //GPS timeout in ms, 120000 (2min) is recommended
            maximumAge: 60000  //Enables the use of cached location. Must be less than timeout
            				   //Special values: 0 always new, Infinity to retrieve last known position.
        };
    try {
            geolocation_so.getCurrentPosition(location_SingleShot_callback, location_SingleShot_error_callback, positionOpts);
    		
        }catch (e) {
            var error = e.toString();
            alert(error);
        }
    When I set enableHighAccuracy to true, I ALWAYS get the following error as alert:

    Error retrieving position code: 0
    message: UnKnown Error
    Is that because it has taken longer than the time-out for being highly accurate? I dont get the error when i dont enableHighAccuracy...
    Without enableHighAccuracy, The accuracy is really quite bad May be because of my location in the globe,or because of me being indoor?

    Google maps application, gives me PIN-POINT, Brilliant accuracy !!!
    I modified the code to render google static maps based on the latitude and longitude I get from my GPS. Still, accuracy sucks!

    Should I use the Service Provider Data, and do something like triangulate it to get accuracy at detecting GPS' latitude and longitude, equivalent to Google Maps application ? (Does Google Maps do that?)
    Please suggest a fix to be able to get the accurate latitude and longitude, the way Google Maps does it to get high accuracy.

    Thanks a lot!
    Vidya Sagar.S

  6. #6
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Unable to use Code Examples for Camera and GPS Positioning together

    Hi,

    That is mostly because you are indoors. It tries to get the GPS position, but fails since there are no satellites in view. "UnKnown Error" is just timeout error in this case.
    Poor accuracy is because network based positioning is used while indoors. In addition if you live far from the cell tower it might be less accurate than usual.

    My advice would be to go outside to see how it works there

    Ps.
    You might be interested on this
    https://projects.forum.nokia.com/ovimapsrenderingapi/

    -Ilkka

Similar Threads

  1. is it possible to find GPS location even GPS Positioning methods are disabled?
    By kuddy_abc in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2010-07-31, 16:24
  2. Why mostly used GPS based positioning than GSM based positioning
    By chatrapati.nokia.santhosh in forum General Development Questions
    Replies: 11
    Last Post: 2010-02-26, 12:59
  3. GPS Positioning
    By NightStalkerDNS in forum Mobile Java General
    Replies: 9
    Last Post: 2009-12-22, 20:33
  4. Replies: 3
    Last Post: 2008-07-10, 10:46
  5. Replies: 4
    Last Post: 2008-04-16, 11:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×