BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-24-2009, 07:55 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2008
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem getting GPS coordinates

Please Login to Remove!

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?
Offline  
Old 03-24-2009, 09:57 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2008
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nevermind, got it working. Thanks for all the replies!
Offline  
Old 03-25-2009, 04:45 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2009
Model: 9000
PIN: N/A
Carrier: T-Mobile
Posts: 67
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you expect a reply and a solution within 2 hours you sarcastic so-and-so?
Offline  
Old 03-25-2009, 09:40 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2008
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by hippocamp software View Post
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.
Offline  
Old 03-25-2009, 09:45 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think editing the first response to your post was an abuse of the edit feature.
__________________
Handspring >> Palm >> BB Pearl >> BB Storm

Tumblog: http://www.geekkink.com
Blog: http://www.zechariahs.org/blog
Offline  
Old 03-25-2009, 09:51 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2009
Model: 9000
PIN: N/A
Carrier: T-Mobile
Posts: 67
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm just shocked and surprised that the official developer forum would be quicker than here!
Offline  
Old 03-25-2009, 10:39 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2008
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by hippocamp software View Post
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.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.