Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Shubhangi
Posts: 97
Registered: ‎07-17-2008
My Device: Not Specified

About GPS Location Listening implementation using simulator

Hi,

 

I have implemented the code to listen for GPS Location.

Also I am not able open "Settings" application on simulator it stucks at black screen with text "BlackBerry 10".

 

Note: If the permission is not set and I ran the program then the GPS location updates are not received.

 

For accessing GPS Location, we need to set permission for application at development time that is "access_location_services" in bar-descriptor.xml file.

 

As soon as I set the permission and run the program, following error is displayed:

Error1.jpg

 

Please help me.

 

Thanks and regards,

Shubhangi

Please use plain text.
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10

Re: About GPS Location Listening implementation using simulator

Can you provide your bar-descriptor.xml file, to see how you specify the access_location_services permission?

Please use plain text.
Developer
Shubhangi
Posts: 97
Registered: ‎07-17-2008
My Device: Not Specified

Re: About GPS Location Listening implementation using simulator

Here is bar-descriptor file:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--
  
   Copyright (c) 2011, 2012 Research In Motion Limited.
  
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
  
   http://www.apache.org/licenses/LICENSE-2.0
  
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
  
-->
<qnx xmlns="http://www.qnx.com/schemas/application/1.0">

<!-- BlackBerry Tablet OS application descriptor file.

    Specifies parameters for identifying, installing, and launching native applications on BlackBerry Tablet OS.

-->

    <!-- A universally unique application identifier. Must be unique across all BlackBerry Tablet OS applications.
         Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
    <id>com.example.TestApp</id>

    <!-- The name that is displayed in the BlackBerry Tablet OS application installer. 
         May have multiple values for each language. See samples or xsd schema file. Optional. -->
    <name>TestApp</name>
    
    <!-- A string value of the format <0-999>.<0-999>.<0-999> that represents application version which can be used to check for application upgrade. 
         Values can also be 1-part or 2-part. It is not necessary to have a 3-part value.
         An updated version of application must have a versionNumber value higher than the previous version. Required. -->
    <versionNumber>1.0.0</versionNumber>

    <!-- Fourth digit segment of the package version. First three segments are taken from the 
         <versionNumber> element.  Must be an integer from 0 to 2^16-1 -->
    <buildId>1</buildId>
                 
    <!-- A string value (such as "v1", "2.5", or "Alpha 1") that represents the version of the application, as it should be shown to users. Optional. -->
    <!-- <versionLabel></versionLabel> -->

    <!-- Description, displayed in the BlackBerry Tablet OS application installer.
         May have multiple values for each language. See samples or xsd schema file. Optional. -->
    <description>The TestApp application</description>

    <!-- Copyright information. Optional. -->
    <!-- <copyright></copyright> -->

    <!--  Name of author which is used for signing. Must match the developer name of your development certificate. -->
    <author>Example Inc.</author>
    
    <!--  Unique author ID assigned by signing authority. Required if using debug tokens. -->
    <!-- <authorId>ABC1234YjsnUk235h</authorId> -->
   
    <initialWindow>
        <systemChrome>none</systemChrome>
        <transparent>false</transparent>
    </initialWindow>
    
    <!--  The category where the application appears. Either core.games or core.media. -->
    <category>core.games</category>
    <configuration name="Device-Debug">
       <platformArchitecture>armle-v7</platformArchitecture>
       <asset path="arm/o.le-v7-g/TestApp" entry="true" type="Qnx/Elf">TestApp</asset>
    </configuration>
    <configuration name="Device-Release">
       <entryPointType>Qnx/Cascades</entryPointType>
       <platformArchitecture>armle-v7</platformArchitecture>
       <asset path="arm/o.le-v7/TestApp.so" entry="true" type="Qnx/Elf">TestApp.so</asset>
    </configuration>
    <configuration name="Device-Profile">
       <platformArchitecture>armle-v7</platformArchitecture>
       <asset path="arm-p/o.le-v7-g/TestApp" entry="true" type="Qnx/Elf">TestApp</asset>
    </configuration>
    <configuration name="Simulator-Debug">
       <platformArchitecture>x86</platformArchitecture>
       <asset path="x86/o-g/TestApp" entry="true" type="Qnx/Elf">TestApp</asset>
    </configuration>
    
    <!--  The icon for the application, which should be 86x86. -->
    <icon>
        <image>icon.png</image>
    </icon>

    <asset path="icon.png">icon.png</asset>
    <asset path="assets">assets</asset>
    
    <!-- Locale support -->
    <asset path="translations" dest="qm">
        <include name="*.qm"/>
    </asset>
    
    <!-- Request permission to execute native code.  Required for native applications. -->
    <permission system="true">run_native</permission>
    <permission>access_location_services</permission>
    <permission>read_geolocation</permission>
    <permission>access_pimdomain_messages</permission>
    <permission>run_when_backgrounded</permission>
    <env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>

</qnx>

 Thanks for response.

 

Please alsoletme know about settings screen as well.

My laptop OS is vista. VMWare4 and new BB10 alpha simulator for gold release.

 

 

Regards,

Shubhangi

Please use plain text.
Developer
Shubhangi
Posts: 97
Registered: ‎07-17-2008
My Device: Not Specified

Re: About GPS Location Listening implementation using simulator

Hi,

 

I have tried testing GPS location retrieving but always updateTimeOut signal is emitted. And in this the error returned is "None->No Error", but still location is not retrieved.

 

As I said, I am not able to set the application permission as well as Simulator permission for location services. Still the my application doesnot throws the error.

 

Kindly help.

 

 

Thanks and regards,

Shubhangi

 

Please use plain text.
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10

Re: About GPS Location Listening implementation using simulator

Hi,

 

First, you can remove the line

<permission>read_geolocation</permission>

from your bar-descriptor.xml, you only need the access_location_services permission. Though this likely won't solve any of your problems. Does the simulator launch ok when you don't specify the access_location_services permission?

 

I presume you have Location Services enabled (i.e. Settings -> Location Services -> Location Services set to on.)

 

As far as the simulator problem goes, it looks like it is having trouble launching (?), this could be related to your bar-descriptor.xml, but not likely related to GPS positioning. It may be a separate issue, better addressed in the Testing and Deployment forum?

 

Are you having trouble on a device as well? Can you provide the section of your code that is trying to get the GPS position?

Please use plain text.
Developer
Shubhangi
Posts: 97
Registered: ‎07-17-2008
My Device: Not Specified

Re: About GPS Location Listening implementation using simulator

Hi,

 

I have removed the line "<permission>read_geolocation</permission>", but still the simulator is not launching.

If I remove all permissions from the bar-descriptor.xml file, simulator launches without any problem.

 

I have not enabled Location Services(i.e. Settings -> Location Services -> Location Services set to on.) because I am not able to open Settings screen on simulator, when I open the settings option from the simulator, only black screen with text "Blackberry 10" is displayed and this screen never goes away.

 

Here is the code to acces gps position:

/* Copyright (c) 2012 Research In Motion Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "KGPSLocationHelper.hpp"

#include "KRawLocationParser.hpp"

#include <bb/cascades/maps/MapData.hpp>
#include <bb/cascades/maps/MapLongPressToPinDrop.hpp>
#include <bb/multimedia/SystemSound>
#include <bb/platform/geo/GeoLocation.hpp>
#include <QtLocationSubset/QGeoPositionInfoSource>
#include <bb/location/PositionErrorCode.hpp>


#include <QtCore/QVariant>

#include <iostream>

using namespace bb::cascades::maps;
using namespace bb::multimedia;
using namespace bb::platform::geo;

//! [0]
KGPSLocationHelper::KGPSLocationHelper(QObject* parent, bool satInfo)
    : QObject(parent)
    , m_latitude(0)
    , m_longitude(0)
    , m_altitude(0)
    , m_positionSource(QGeoPositionInfoSource::createDefaultSource(this))
{
    if (m_positionSource)
    {
    	bool positionUpdatedConnected = connect(m_positionSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(positionUpdated(const QGeoPositionInfo &)));

    	QString strMessage = "";
    	//fprintf(stdout,  "%s\n", ("" + positionUpdatedConnected).toAscii().constData());
        //fflush(stdout);
    	log(tr("Flag: " + positionUpdatedConnected));

    	if(positionUpdatedConnected)
    	{
    	    // positionUpdated() SIGNAL connected.
    		//log(tr("positionUpdated() SIGNAL connected."));
    	    // Get the position of the device
    		//m_positionSource->requestUpdate(120000);
    		//requestUpdate();
    	}
    	else
    	{
    		log(tr("positionUpdated() SIGNAL failed to connect."));
    	}

        connect(m_positionSource, SIGNAL(updateTimeout()), this, SLOT(positionUpdateTimeout()));

        log(tr("Initialized QGeoPositionInfoSource"));
    } else {
        log(tr("Failed to initialized QGeoPositionInfoSource"));
    }
    m_direction = m_horizontalAccuracy = m_verticalAccuracy = m_magneticVariation = tr("--");
    m_time = tr("-/-/- -:-");
    m_groundSpeed = tr("-- km/h");
    m_verticalSpeed = tr("-- km/h");
}
//! [0]

//! [1]
void KGPSLocationHelper::startUpdates()
{
	//m_positionSource->s
	QString strMessage = "In startUpdates...";
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    fflush(stdout);
    if (m_positionSource)
    {
    	QString strMessage = "Update start...";
		fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
		fflush(stdout);
        m_positionSource->startUpdates();
        log(tr("Position updates started"));
    }
}
//! [1]

//! [2]
void KGPSLocationHelper::requestUpdate()
{
    if (m_positionSource) {
        m_positionSource->requestUpdate(120000);
        log(tr("Update requested"));
    }
}
//! [2]

//! [3]
void KGPSLocationHelper::stopUpdates()
{
    if (m_positionSource) {
        m_positionSource->stopUpdates();
        log(tr("Position updates stopped"));
    }

    deleteLater();
}
//! [3]

//! [4]
void KGPSLocationHelper::resetSession(const QString &type)
{
    if (m_positionSource) {
        m_positionSource->stopUpdates();
        m_positionSource->setProperty("reset", type);
        m_positionSource->startUpdates();
        log(tr("%1 RESET").arg(type));
    }
}
//! [4]

//! [5]
void KGPSLocationHelper::positionUpdated(const QGeoPositionInfo& pos)
{
    //if (m_soundEnabled)
    //    SystemSound::play(SystemSound::GeneralNotification);

    m_latitude = pos.coordinate().latitude();
    m_longitude = pos.coordinate().longitude();
    m_altitude = pos.coordinate().altitude();
    m_time = pos.timestamp().toString();
    m_direction = QString::number(pos.attribute(QGeoPositionInfo::Direction));
    m_groundSpeed = QString::number(pos.attribute(QGeoPositionInfo::GroundSpeed));
    m_verticalSpeed = QString::number(pos.attribute(QGeoPositionInfo::VerticalSpeed));
    m_horizontalAccuracy = QString::number(pos.attribute(QGeoPositionInfo::HorizontalAccuracy));
    m_verticalAccuracy = QString::number(pos.attribute(QGeoPositionInfo::VerticalAccuracy));
    m_magneticVariation = QString::number(pos.attribute(QGeoPositionInfo::MagneticVariation));

	QString strMessage = "Latitude: ";
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    fflush(stdout);

    /*strMessage  = "" + m_latitude;
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    fflush(stdout);*/

	strMessage = "Longitude: ";
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    fflush(stdout);

	/*strMessage = "" + m_longitude;
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    fflush(stdout);*/

    strMessage = "Speed: ";
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
	fflush(stdout);

	//strMessage = "Setting Property...";
	fprintf(stdout,  "%s\n", m_verticalSpeed.toAscii().constData());
	fflush(stdout);


    parseRawData();

    emit dataChanged();

    log(tr("update"));
}
//! [5]

QGeoPositionInfoSource* KGPSLocationHelper::positionSource() const
{
    return m_positionSource;
}

void KGPSLocationHelper::positionUpdateTimeout()
{
    log(tr("positionUpdateTimeout() received"));

    if (m_positionSource->property("replyErrorCode").isValid())
    {
    	QVariant variant = m_positionSource->property("replyErrorCode");
    	QString strMessage = variant.toString();
    	log(tr("LM Error Code: "));
    	//log(strMessage);
    	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    	fflush(stdout);

    	bb::location::PositionErrorCode::Type errorCode = m_positionSource->property("replyErrorCode").value<bb::location::PositionErrorCode::Type>();

        switch(errorCode)
        {
            case bb::location::PositionErrorCode::None:
            	log(tr("None"));
                break;

            case bb::location::PositionErrorCode::FatalDisabled:
            	log(tr("Fatal - disabled (turn on location services!)"));
                break;

            case bb::location::PositionErrorCode::FatalNoLastKnownPosition:
            	log(tr("Fatal - no last known position"));
                break;

            case bb::location::PositionErrorCode::FatalInsufficientProviders:
            	log(tr("Fatal - insufficient providers"));
                break;

            case bb::location::PositionErrorCode::FatalInvalidRequest:
            	log(tr("Fatal - invalid request"));
                break;

            case bb::location::PositionErrorCode::WarnTimeout:
            	log(tr("Warning - timeout"));
                break;

            case bb::location::PositionErrorCode::WarnLostTracking:
            	log(tr("Warning - lost tracking"));
                break;

            case bb::location::PositionErrorCode::WarnStationary:
            	log(tr("Warning - stationary"));
                break;

            default:
            	log(tr("Unknown (bad enum value)"));
                break;
        }
    }

    QString strLog = this->log();
	fprintf(stdout,  "%s\n", strLog.toAscii().constData());
	fflush(stdout);
}


void KGPSLocationHelper::parseRawData()
{
    // Parsing the raw data from the low level Location Manager. Use this only if a field is not accessible via QGeoPositionInfo above.
    const QVariant replyData = (m_positionSource ? m_positionSource->property("replyDat") : QVariant());

    if (!replyData.isValid()) {
        log(tr("!!! Invalid replyDat."));
    }

    KRawLocationParser parser(replyData);

    m_method = parser.positionMethod();
    //m_horizontalDilution = QString::number(parser.hdop());
    //m_verticalDilution = QString::number(parser.vdop());
    //m_positionDilution = QString::number(parser.pdop());
    //m_ttff = QString::number(parser.ttff());
    //m_gpsWeek = QString::number(parser.gpsWeek());
    //m_gpsTimeOfWeek = QString::number(parser.gpsTow());
    //m_isPropagated = parser.propagated();

    const double latitude = parser.latitude();
    const double longitude = parser.longitude();
    const double altitude = parser.altitude();
    const double hAccuracy = parser.horizontalAccuracy();
    const double vAccuracy = parser.verticalAccuracy();
    const double heading = parser.heading();
    const double speed = parser.speed();
    const double utc = parser.utc();

    log(
            tr("Method: %0, Latitude: %1, Longitude: %2, Altitude: %3, Horizontal Accuracy: %4, Vertical Accuracy: %5, Heading: %6, Speed: %7, ").arg(m_method).arg(latitude).arg(longitude).arg(altitude).arg(hAccuracy).arg(vAccuracy).arg(heading).arg(speed), false);
                    //+ tr("GPS TOW: %0, UTC: %1, Horizontal Dilution: %2, Vertical Dilution: %3, Positional Dilution: %4, Propagated: %5").arg(m_gpsTimeOfWeek).arg(utc).arg(m_horizontalDilution).arg(m_verticalDilution).arg(m_positionDilution).arg(m_isPropagated ? tr("true") : tr("false")), false);

    const QString error = parser.error();
    if (error.length() > 3) {
        log(tr("!!! [Error] %1").arg(error));
    }

    for (int i = 0; i < parser.numberOfSatellites(); i++) {
        const double id = parser.satelliteId(i);
        const double cno = parser.satelliteCarrierToNoiseRatio(i);
        const bool ephemerisAvailable = parser.satelliteEphemerisAvailable(i);
        const double azimuth = parser.satelliteAzimuth(i);
        const double elevation = parser.satelliteElevation(i);
        const bool tracked = parser.satelliteTracked(i);
        const bool used = parser.satelliteUsed(i);

        log(tr("\t[Satellite %0], ID: %1, CNO: %2, Ephemeris Available: %3, Azimuth: %4, Elevation: %5, Tracked: %6, Used: %7").arg(i).arg(id).arg(cno).arg(ephemerisAvailable ? tr("true") : tr("false")).arg(azimuth).arg(elevation).arg(tracked ? tr("true") : tr("false")).arg(used ? tr("true") : tr("false")), false);
    }
}

void KGPSLocationHelper::log(const QString &msg, bool showInUi)
{
    std::cout << msg.toStdString() << std::endl;
    if (showInUi) {
        m_log += msg + QLatin1String("\n");
        emit logChanged();
    }
}

QString KGPSLocationHelper::method() const
{
    return m_method;
}

double KGPSLocationHelper::latitude() const
{
    return m_latitude;
}

double KGPSLocationHelper::longitude() const
{
    return m_longitude;
}

double KGPSLocationHelper::altitude() const
{
    return m_altitude;
}

QString KGPSLocationHelper::time() const
{
    return m_time;
}

QString KGPSLocationHelper::direction() const
{
    return m_direction;
}

QString KGPSLocationHelper::groundSpeed() const
{
    return m_groundSpeed;
}

QString KGPSLocationHelper::verticalSpeed() const
{
    return m_verticalSpeed;
}

QString KGPSLocationHelper::horizontalAccuracy() const
{
    return m_horizontalAccuracy;
}

QString KGPSLocationHelper::verticalAccuracy() const
{
    return m_verticalAccuracy;
}

QString KGPSLocationHelper::magneticVariation() const
{
    return m_magneticVariation;
}

QString KGPSLocationHelper::log() const
{
    return m_log;
}

 

And this is KGPSLocationListener:

/*
 * KGPSLocationListener.cpp
 *
 *  Created on: Dec 21, 2012
 *      Author: shubhangi.gajare
 */

#include "KGPSLocationListener.hpp"
#include "KGPSLocationHelper.hpp"

KGPSLocationListener::KGPSLocationListener(QObject *parent): QObject(parent)
{
	// TODO Auto-generated constructor stub
}

KGPSLocationListener::~KGPSLocationListener()
{
	// TODO Auto-generated destructor stub
}

KGPSLocationHelper* KGPSLocationListener::createLocationHelper(bool trackingMode)
{
	QString strMessage = "In createLocationHelper...";
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    fflush(stdout);
    // Create a new location session
    KGPSLocationHelper* session = new KGPSLocationHelper(this, true);

	strMessage = "Setting Property...";
	fprintf(stdout,  "%s\n", strMessage.toAscii().constData());
    fflush(stdout);
    if (!session->positionSource())
        return session;

    //session->positionSource()->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);
    //session->positionSource()->setProperty("provider", "gnss");
    //session->positionSource()->setProperty("fixType", "gps_autonomous");

    //session->positionSource()->setProperty("provider", "network");
    //session->positionSource()->setProperty("fixType", "wifi");

    session->positionSource()->setUpdateInterval(1000);
    session->positionSource()->setProperty("canRunInBackground", true);

    // Activate the session
    if (trackingMode) {
        session->startUpdates();
    } else {
        session->requestUpdate();
    }

    return session;
}

 Let me know your response.

Also I will post the issue of launching simulator and settings screen on Testing ans Deployment forum.

 

 

Thanks and regards,

Shubhangi

 

 

 

 

Thanks and regards,

Please use plain text.
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10

Re: About GPS Location Listening implementation using simulator

Hi,

 

You must have both Location Services permission for your app, and Location Services enabled on the device/simulator before GPS positioning will work at all, so hopefully you can first get the simulator issue worked out quickly.

 

I scanned your code and don't see any obvious problems, so hopefully it will work once the simulator is working for you. 

 

Regards,

Jim

Please use plain text.
Regular Visitor
dengineer
Posts: 1
Registered: ‎02-12-2013
My Device: Z10

Re: About GPS Location Listening implementation using simulator

[ Edited ]

Adding GPS to your app is quick and easy. If your using Cascades (QML) then follow these steps:

  1. Add Location Permission to your Project

  2. Add Qt Mobility to your QML app:

    //! GPS Variables
    property string latitude
    property string longitude
    property variant currentCoord

  3. Add the Qt Mobility Library

    import QtMobilitySubset.location 1.1

     

  4. Attach Position Source to the page

    attachedObjects: [PositionSource {
    id: positionSource//! Desired interval between updates in milliseconds
    updateInterval: 10000//! When position changed, update the location strings
    onPositionChanged: {
    currentCoord = positionSource.position.coordinate;
    latitude = currentCoord.latitude;
    longitude = currentCoord.longitude;
    console.debug(latitude, longitude);
    positionSource.stop();}
    }
    ]

     

  5. Start PositionSource

    positionSource.start()

    Step by Step Video Guide
Please use plain text.