0

I am a newbie in Blackberry.I tried with finding the latitudes and longitudes . I used the below code, but it always returns 0.0, 0.0 for both latitude and longitudes. Can somone make sure whether i have picked up the right code.(or) am i doing wrong some where.

Even i tried with setting the latitude and longitude in the BB simulator too . (Simulate->GPS Location-> Added a new Loaction), but still getting the lat & lon as (0.0,0.0).

Please find the code that i tried with,

// Locationfinder.java

package com.beacon.bb.app;

import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;

import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;


 public class LocationFinder extends MainScreen  {

private int _interval = -1;
private double mLatitude, mLongitude;

public LocationFinder() {
     super(); 
     // Set criteria for selecting a location provider:
     Criteria cr= new Criteria();
     cr.setCostAllowed(true);
     cr.setPreferredResponseTime(60);
     cr.setHorizontalAccuracy(5000);
     cr.setVerticalAccuracy(5000);
     cr.setAltitudeRequired(true);
     cr.isSpeedAndCourseRequired();
     cr.isAddressInfoRequired();
     add(new RichTextField("Getting Coordinates...."));
     try{    
         LocationProvider lp = LocationProvider.getInstance(cr);
         if( lp!=null ){

               lp.setLocationListener(new LocationListenerImpl(), _interval, 1, 1); 
         }           
         add(new RichTextField("Calulating GPS Cordinates :"));
         add(new RichTextField("Latitude  :" + mLatitude  + "," + "Longitude :" + mLongitude));
         //System.out.println("Lon" + longitude + " Lat "+ latitude + " course "+course+" speed "+speed+" timestamp "+timestamp);
 }
 catch(LocationException le)
 {
         add(new RichTextField("Location exception "+le));
 }

 }

private class LocationListenerImpl implements LocationListener { 
    public void locationUpdated(LocationProvider provider, Location location) {
            if(location.isValid()) {
                   double longitude = location.getQualifiedCoordinates().getLongitude();
                    double latitude = location.getQualifiedCoordinates().getLatitude();
                    double altitude = location.getQualifiedCoordinates().getAltitude();
                    float speed = location.getSpeed(); 
                    System.out.println("Lon" + longitude + " Lat "+ latitude + " speed "+speed);
                    mLatitude = latitude;
                    mLongitude  = longitude;

            }
    }

    public void providerStateChanged(LocationProvider provider, int newState) {
            // MUST implement this.  Should probably do something use ful with it as well.
    }
    }
    }
j0k
  • 22,600
  • 28
  • 79
  • 90
Nandagopal T
  • 2,037
  • 9
  • 42
  • 54
  • 1
    I found sometimes that you have to set the coordinates prior to launching your app on the simulator. Give that a try and see if it lets you use simulated coordinates. – jprofitt Apr 19 '11 at 16:49

1 Answers1

0

u have set the _interval to -1 which should be a valid time in seconds. i means _interval value indicates after how much time the location will be listened.

also try this link:

Current latitude and longitude in a BlackBerry app

Community
  • 1
  • 1
Swati
  • 2,870
  • 7
  • 45
  • 87