开发者

Simulating the Latitudes and Longitudes in BlackBerry Simulator

I am a newbie in Blackberry.I tried with finding the latitudes and longitudes . I used the belo开发者_JAVA技巧w 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.
    }
    }
    }


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜