Search code examples
androidroutesnavigationskmapsskobbler-maps

Is there any way to get the SKPostion on NavigationStarted?


I am trying to get the Points(coordinates) traveled on the Route while navigating. SKnavigationState does not provide any latlon coordinates on ongoing navigation to the route.

How do I get the coordinates of the user's position on the route while navigation is taking place?


Solution

  • There are a number of ways of doing this:

    
        private void startNavigation() 
        { 
            //..... navigation settings 
            if (configuration.getNavigationType() == SKNavigationSettings.SKNavigationType.REAL) { 
                navigationSettings.setNavigationType(SKNavigationSettings.SKNavigationType.REAL); 
                Date date = new Date(); 
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); 
                final File navigationLogsFolder =  new File(Environment.getExternalStorageDirectory() + File.separator + "LogFileName" + File.separator); 
                if (!navigationLogsFolder.exists()) { 
                    navigationLogsFolder.mkdirs(); 
                } 
                final String fileName = navigationLogsFolder.getAbsolutePath() + "/" + dateFormat.format(date); 
                SKPositionLoggingManager.getInstance().startLoggingPositions(fileName, SKPositionLoggingManager.SPositionLoggingType.SK_POSITION_LOGGING_TYPE_LOG); 
            } 
            navigationManager.startNavigation(navigationSettings); 
        } 
    
    When you want to stop the logging process please call SKPositionLoggingManager().stopLoggingPositions()

    • when receiving a location update (or any other time) you can ask & log the currently known position via the getCurrentGPSPosition API ( via the matched paremeter you can ask either for the real position or the "matched on road" position)