BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   Problem getting GPS coordinates (http://www.blackberryforums.com/showthread.php?t=182855)

GasBot 03-24-2009 07:55 PM

Problem getting GPS coordinates
 
Here's the code I'm using trying to get GPS coordinates. It seems like every time it times out and ends up returning 0 for both the latitude and longitude even though I've both set a location in my Simulate -> GPS Location.. window and gone into the Options -> Advanced Options -> GPS -> Refresh Location.

In my main application class this function gets called from a button.
Code:

public void GetCurrentLocation() {
        Criteria ct = new Criteria();
        //ct.setAddressInfoRequired(false);
        //ct.setAltitudeRequired(false);
        ct.setCostAllowed(true);
        ct.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
        ct.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
        ct.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
        //ct.setPreferredResponseTime(10000);
        //ct.setSpeedAndCourseRequired(false);
       
        try {
            myLP = LocationProvider.getInstance(ct);
            myLP.setLocationListener(new myLocListener(this), -1, -1, -1);
        } catch (Exception ex) {
            return;
        }
    }

public void GotLocation(Location myLoc) {
        if(myLoc != null) {
            QualifiedCoordinates qc = myLoc.getQualifiedCoordinates();
            //Call webservice here.
        }
    }

In the myLocListener.java
Code:

package net.gasbot;

import javax.microedition.location.*;

public class myLocListener implements LocationListener
{
    GasBotScreen gb;
   
    public myLocListener(GasBotScreen gb)
    {
        this.gb = gb;
    }
   
    public void locationUpdated(LocationProvider provider, Location location)
    {
        QualifiedCoordinates qc = location.getQualifiedCoordinates();  //I set a breakpoint here, but it rarely gets called, and when it does, the coordinates are both 0.
        provider.setLocationListener(null, 0, 0, 0);
        gb.GotLocation(location);
    }

    public void providerStateChanged(LocationProvider provider, int newState)
    {
       
    }
}

Can someone please let me know what I'm doing wrong? I'm setting the listener to null after it gets an updated location as I only need it once.

I've also tried using the .getLocation(-1) and it doesn't work either. Is there something wrong with my simulator? Or just something wrong with my code?

GasBot 03-24-2009 09:57 PM

Nevermind, got it working. Thanks for all the replies!

hippocamp software 03-25-2009 04:45 AM

you expect a reply and a solution within 2 hours you sarcastic so-and-so?

GasBot 03-25-2009 09:40 AM

Quote:

Originally Posted by hippocamp software (Post 1332012)
you expect a reply and a solution within 2 hours you sarcastic so-and-so?

A reply, maybe not a solution. But the official BlackBerry support forums had several replies before this one despite me posting it there an hour later than here.

zechariahs 03-25-2009 09:45 AM

I think editing the first response to your post was an abuse of the edit feature.

hippocamp software 03-25-2009 09:51 AM

i'm just shocked and surprised that the official developer forum would be quicker than here!

GasBot 03-25-2009 10:39 AM

Quote:

Originally Posted by hippocamp software (Post 1332280)
i'm just shocked and surprised that the official developer forum would be quicker than here!

Honestly, I am shocked. Usually I get more help from enthusiast websites like these than the corporate run forums.


All times are GMT -5. The time now is 08:28 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.