×

Discussion Board

Results 1 to 5 of 5

Thread: Landmarks API

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    4

    Landmarks API

    Hi

    I've been experimenting with the Landmarks example and can get that working fine in the emulator.
    I'd like to be able to return landmarks filtered by the nearest first and am having difficulty in achieving this.
    I've modified the getListLandmarks function and added the following:

    Code:
    var lmp = new Object();
        
    lmp.Latitude = 1;
    lmp.Longitude = 1;
    lmp.Altitude = 0;
    
    criteria.Filter = new Object();
    criteria.Filter.LandmarkPosition = lmp;
    However the results are not sorted closest to the position specified. Can anyhow shed light on how to do this properly?

    I've looked at the documention as carefully as I could but cannot make sense of how to achieve this simple task.

  2. #2
    Super Contributor
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Landmarks API

    Hello esoteric,

    Welcome to forum

    It seems that sorting by location is not supported. Landmarks can only be sorted by LandmarkName. There is no ready-made API for sorting, but you should be able to calculate the distance, with Location Service API. Of course then you would have to sort items by your self.

    Best Regards,
    Ilkka - Forum Nokia

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    4

    Re: Landmarks API

    Thanks for the welcome isalento.

    I've arrived at the same conclusion, it seems I can get the information I require but it isn't sorted the way I'd like it. However I have found a solution.

    To achieve this, specify:

    Code:
        criteria.Filter.MaximumDistance = 1000 * required_km;
        criteria.Filter.MaximumMatches = 1;
    The important thing to note here is criteria.Filter.MaximumMatches, with a value of 1, it'll be a sorted "list" ;-)

    I hope that this is helps others.

  4. #4
    Super Contributor
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Landmarks API

    Hi,

    Thank you for sharing the solution. I did not spot that and it is not in the documentation

    Here is some my contribution for this matter. Maybe I will write a wiki article based on this, but until then, here is a unpolished solution to obtain and sort nearby landmarks.'

    Code:
    window.onload = init;
    
    var landmarksSo = null;
    var locationSo=null;
    
    //hard coded please change				
    var currentPos = new Object();
    currentPos.Longitude = 23.861260972;
    currentPos.Latitude  = 61.447976734;
    
    function init()
    {
        try {
            landmarkSo = device.getServiceObject("Service.Landmarks", "IDataSource");
    	locationSo = device.getServiceObject("Service.Location", "ILocation");
    		
    	//position, distance in meters
    	getLandmarks(currentPos,100000000);
        } 
        catch (e) {
            alert("So init: "+ e.toString());
        }	
    		
    }	
    
    function calclulateDistance(currentPos, landmarkPos){
    		
    	var criteria = new Object();
    	criteria.MathRequest = "FindDistance";
    	criteria.DistanceParamSource = currentPos;
    	criteria.DistanceParamDestination = landmarkPos;
    	
    	//altitude must be present altough it does not affect the result
    	criteria.DistanceParamSource.Altitude=0;
    	criteria.DistanceParamDestination.Altitude=0;
    		
    	result = locationSo.ILocation.Calculate(criteria);
    	
    	if (result.ErrorCode != 0) {
    	        writeLine(result.ErrorCode +": "+result.ErrorMessage);
    		return -1;
    	}
    	else {
    		return result.ReturnValue;
    	}
    }
    
    
    function distanceToHumanReadable(distance){
    	var dipDist="";
    					
    	if (distance > 1000) {
    		distance = Math.round(distance / 100)/10;
    		dipDist = distance  + " km";
    	}
    	else {						
    		dipDist = Math.round(distance) + " m";
    	}
    	return dipDist;
    }
    
    function sortLandmarks(a, b) {	
    	if(a[1]< b[1])
    		return -1;
    	
    	if(a[1] > b[1])
    		return 1;
    	
    	//a[1] == b[1] sort alphabetically
    	var nameA=a[0].LandmarkName.toLowerCase();
    	var nameB=b[0].LandmarkName.toLowerCase();
    	
    	if(nameA < nameB)
    		return -1;
    	if(nameA > nameB)
    		return 1;
    	
    	return 0;
    }
    
    function getLandmarks(position, maxDistance){
    		
    	try {
    	var criteria = new Object();
    	criteria.Type = "Landmark";
    		
    	var filter = new Object();
    	criteria.Filter = filter;
    		
    	criteria.Filter.MaximumMatches = 10;
    	criteria.Filter.MaximumDistance = maxDistance; //meters
    	criteria.Filter.CoverageRadiusOption = true;
    	criteria.Filter.LandmarkPosition = position;
    				
    	var result = landmarkSo.IDataSource.GetList(criteria,landmarksGot);
    				
    	writeLine("listLandmarks "+ result.TransactionID +" "+ result.ErrorCode +" "+result.ErrorMessage);
        } 
        catch (e) {
            var error = e.toString();
            alert("Error getLandmarks: "+error);
        }
    }
    
    function landmarksGot(transactionID, eventCode, result){
    	switch(eventCode) {
    		case 2:
    		    {
    			writeLine("List of landmarks");  
    			var list = result.ReturnValue;
    			
    			var landmark = null;
    	        	var landmarks= new Array();
    			var i=0;       
    			while ((landmark = list.getNext()) != undefined) {		
    								
    				var distance = calclulateDistance(currentPos,landmark.LandmarkPosition);
    				landmarks[i]= new Array();
    				landmarks[i][0] = landmark; 
    				landmarks[i][1] = distance;		
    				i++;			
    	    	    }
    			writeLine("sortLandmarks ");
    			landmarks.sort(sortLandmarks);
    								
    			for(lm in landmarks){
    				writeLine(landmarks[lm][0].LandmarkName+" dist "+distanceToHumanReadable(landmarks[lm][1]));				             
    			}
    			}
    			break;
    		case 4: 
    			//show loader etc..
    			writeLine("loading landmarks");
    			break;
    		
    		case 9: 
    			writeLine("Error while retrieving landmarks: "+ result.ErrorMessage + " code:"+ result.ErrorCode);
    			break;
    	
    		default: 
    			alert("oops something went wrong"+ eventCode);
    	}
    }
    
    function writeLine(line){
    	document.getElementById("stdout").innerHTML += line+"<br>";
    }
    Br,
    Ilkka - FN

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: Landmarks API

    Hi esoteric & isalento,

    thanks for sharing these code snippets!

    Pit

Similar Threads

  1. How to use Google map API on Symbian /S60 platform
    By zhang_guoqing in forum Symbian
    Replies: 2
    Last Post: 2009-02-21, 20:44
  2. How can i access Calendar database using PC Connectivity SDK?
    By sazzad_101 in forum PC Suite API and PC Connectivity SDK
    Replies: 8
    Last Post: 2009-02-18, 14:49
  3. Replies: 1
    Last Post: 2009-02-08, 12:31
  4. PC Suite error: (Code: Init IMediaControl2) HELP?!
    By chunkyspudmonkey in forum General Development Questions
    Replies: 29
    Last Post: 2008-06-30, 11:47
  5. Is there a C++ API for the video player
    By avbrozhko in forum Symbian
    Replies: 9
    Last Post: 2008-06-06, 14:34

Posting Permissions

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