GPS Lat Lon Issue in Blackberry Storm - blackberry

I Write the following code in my application.
It will run successfully in Simulator but while i m trying to run in my device then it gives Lat & Lon (0.0,0.0).
What is the problem.
My Code is .
public class GetLatLon extends TimerTask{
public static Timer timer;
private double longitude;
private double latitude;
public GetLatLon(int duration) {
timer = new Timer();
try {
// TODO: update criteria with desired location distances, etc
LocationProvider.getInstance(new Criteria()).setLocationListener(
new MyLocationListener(), 1, 1, 1);
} catch (Exception e) {
System.err.println(e.toString());
}
timer.schedule(this, 0, 10000);
}
public void run() {
System.out.println("Lattitude :-"+ latitude);
System.out.println("Longitude :-"+ longitude);
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
private class MyLocationListener implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location) {
if (location != null && location.isValid()) {
QualifiedCoordinates qc = location.getQualifiedCoordinates()
try {
GetLatLon.this.longitude = qc.getLongitude();
GetLatLon.this.latitude = qc.getLatitude();
} catch (Exception e) {
System.err.println("criccomini " + e.toString());
}
} else {
System.err.println("criccomini location not valid");
}
}
public void providerStateChanged(LocationProvider provider, int newState) {
}
}
}

I had also faced same problem with 9550 Storm-2.
I think you face the problem due to your device GPS value does not initiate properly. Try to use this tool :
http://appworld.blackberry.com/webstore/content/12255
this will initiate the GPS values(Plz don't close this tool just send it to background by pressing red key).After initiate the GPS value try to run you application.
i hope problem will be solved. ;)

Here No issue with code
Gps is not supported 5.0 OS with LAN ,so
I provide you some guides please verify.
Introduction to GPS and BlackBerry video.
The BlackBerry smartphone models and their corresponding GPS capabilities
How to detect whether my BB device has GPS support?
Some GPS Related Issues
Best practices for designing GPS applications for BlackBerry smartphones operating on CDMA networks
this is full information about blackberry GPS support

Related

MVVMCross IMvxGeoLocationWatcher Success Action never fires on Android

I created a very simple test app to try and reverse geocode my current lat/long into an address.
Here is the code for my ViewModel:
namespace LoginProductsMVVM.Core.ViewModels
{
public class ProductDetailViewModel
: MvxViewModel
{
public void Init(Product product)
{
Product = product;
}
private Product _product;
public Product Product
{
get { return _product; }
set { _product = value;
RaisePropertyChanged (() => Product); }
}
private string _latitude;
public string Latitude{
get { return _latitude; }
set { _latitude = value; RaisePropertyChanged(() => Latitude); }
}
private string _longitude;
public string Longitude{
get { return _longitude; }
set { _longitude = value; RaisePropertyChanged(() => Longitude); }
}
private string _address;
public string Address{
get { return _address; }
set { _address = value; RaisePropertyChanged(() => Address); }
}
private IMvxGeoLocationWatcher _watcher;
public IMvxGeoLocationWatcher Watcher
{
get
{
_watcher = Mvx.Resolve<IMvxGeoLocationWatcher> ();
return _watcher;
}
}
public ProductDetailViewModel(IMvxGeoLocationWatcher watcher)
{
_watcher = watcher;
_watcher.Start (new MvxGeoLocationOptions (), OnLocation, OnError);
}
void OnLocation (MvxGeoLocation location)
{
Latitude = location.Coordinates.Latitude.ToString();
Longitude = location.Coordinates.Longitude.ToString();
// Android Location specific stuff
var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity> ().Activity;
Geocoder geocdr = new Geocoder (activity.BaseContext);
IList<Address> addresses = geocdr.GetFromLocation (double.Parse(Latitude), double.Parse(Longitude), 1);
addresses.ToList().ForEach ((addr) => Address += addr.ToString() + "\r\n\r\n");
}
void OnError (MvxLocationError error)
{
Mvx.Error ("Seen location error {0}", error);
}
}
}
I have a break point in my OnLocation method but it never gets in there. Am I missing something for this to work properly on Android? It appears to work just fine for iOS...
Per Odahan here:
Well... I investigated a bit more : The problem is known and can be seen on many devices. This is not a MvvmCross problem. Short answer : the device needs to be rebooted and all is working like a charm... It seems Google sent some updates that are causing the problem.
Here is a thread speaking about this problem and a similar one concerning the GeoCode class :
https://code.google.com/p/android/issues/detail?id=38009
So : can be closed, MvvmCross is ok but others can face this bug so my explanations and the link here.
When you say it never fires 'success', does the success actually ever occur?
There could be lots of things going wrong in the GPS code - eg your app might not have privilege, your phone might have A-GPS or GPS disabled, or you might even be running on a location-less emulator - all of this is possible from your description.
It'a also worth noting that Xamarin.Android has long standing issues with hitting breakpoints - so it's better to add trace than to rely on breakpoint hitting :/
Perhaps try running though N=8 from http://mvvmcross.wordpress.com/ - does that help at all? (N=9 is also worth watching as it shows one way to allow multiple viewmodels to use the geowatcher)

Blackberry issue on cell site GPS tracking

In my BB app, I try to fetch the location using the cell site.
But it always throws a Location exception:
Timed out while waiting for Geolocation.m=0
Here is my code
Criteria criteria = new Criteria();
criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setCostAllowed(true);
criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
LocationProvider provider = LocationProvider.getInstance(criteria);
Location location = provider.getLocation(-1);
QualifiedCoordinates qualifiedCoordinates = location.getQualifiedCoordinates();
double latitude = qualifiedCoordinates.getLatitude();
double longitude = qualifiedCoordinates.getLongitude();
But if i change the parameters to
criteria.setHorizontalAccuracy(50);
criteria.setVerticalAccuracy(50);
criteria.setCostAllowed(true);
criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
the assisted GPS works fine and I will get the correct location of device.
class LocationTracker{
private LocationProvider provider;
Criteria cr;
public LocationTracker() {
cr= new Criteria();
resetGPS();
}
public void resetGPS(){
try {
provider = LocationProvider.getInstance(cr);
if(provider != null) {
provider.setLocationListener(new MyLocationListener(),60, -1, -1);
}
}
catch (LocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class MyLocationListener implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location){
if(location != null && location.isValid()){
QualifiedCoordinates qc = location.getQualifiedCoordinates();
try {
LAT = location.getQualifiedCoordinates().getLatitude();
System.out.println("=============================lattitude :: "+LAT);
LONG= location.getQualifiedCoordinates().getLongitude();
System.out.println("==================================longitude ::"+LONG);
}
catch(Exception e){
}
}
}
public void providerStateChanged(LocationProvider provider, int newState){
if(newState == LocationProvider.TEMPORARILY_UNAVAILABLE){
provider.reset();
provider.setLocationListener(null, 0, 0, -1);
}
}
}
Like vijay, you can register to location update.
If you still want to use your solution, you have to be sure that
- It is threaded (and not just only not to get an ANR, it is a requirement)
- You have a SIM card with a Blackberry option
- You run on at least OS 5.0.0

get current location from GPS in Blackberry application

How to get current location from GPS in Blackberry application. I tried to get location from Locationmanager method in simulator its work fine but in my device (Storm 2 using wifi) I am not able to get current lat long.
my code
private class LocationListenerImpl implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location) {
if (location.isValid()) {
heading = location.getCourse();
longitude = location.getQualifiedCoordinates().getLongitude();
latitude = location.getQualifiedCoordinates().getLatitude();
altitude = location.getQualifiedCoordinates().getAltitude();
speed = location.getSpeed();
// This is to get the Number of Satellites
String NMEA_MIME = "application/X-jsr179-location-nmea";
satCountStr = location.getExtraInfo("satellites");
if (satCountStr == null) {
satCountStr = location.getExtraInfo(NMEA_MIME);
}
// this is to get the accuracy of the GPS Cords
QualifiedCoordinates qc = location.getQualifiedCoordinates();
accuracy = qc.getHorizontalAccuracy();
}
}
public void providerStateChanged(LocationProvider provider, int newState) {
// no-op
}
}
I found this on the first place I looked for storm issues : If you run the above code on your BlackBerry device (for instance a Storm), you will get a "GPS not allowed" LocationProvider exception. You need to get your code signed if you want to use the BlackBerry Storm with GPS in your app. To do this, you need to buy a $20 certificate from RIM.

Blackberry - change latitude and longitude on the device to test app

I want to test my app on the device. Is it possible to hard code the latitude and longitude values somewhere in the device settings so the app reads those instead of the current location?
I want to test my app for different locations other than my current location.
In the BB simulator you can go to Simulate > GPS Location. Click the Add button and enter in a name, latitude and longitude. Click save and the simulator will start feeding your new location to the apps. Note that whatever location is displayed in the drop down is the one that will be reported by the simulator.
Inside GPS mockup
If you have access to your application code, you can always create a mockup implementation for LocationProvider so it will read location and speed data from file or RecordStore and return it as a Location, something like
public class MockupLocationProvider extends LocationProvider {
public MockupLocationProvider() {
//prepare a file or RecordStore with locations here
}
public Location getLocation(int arg0) throws LocationException,
InterruptedException {
//read data from file or RecordStore
double latitude = 321;
double longitude = 34;
float altitude = 21;
//create and return location
Location result = new GPSLocation(latitude,
longitude, altitude);
return result;
}
public int getState() {
// mockup location provider always available
return LocationProvider.AVAILABLE;
}
public void reset() {
// your code
}
public void setLocationListener(LocationListener listener,
int interval, int timeout, int maxAge) {
// your code
}
}
and mockup for your Location
public class GPSLocation extends Location {
double _latitude, _longitude;
float _altitude, _horAcc = 0, _verAcc = 0, _speed;
public GPSLocation(double lat, double lon, float alt) {
init(lat, lon, alt);
}
public GPSLocation(double lat, double lon, float alt, float spd) {
init(lat, lon, alt);
_speed = spd;
}
private void init(double lat, double lon, float alt) {
_latitude = lat;
_longitude = lon;
_altitude = alt;
}
public QualifiedCoordinates getQualifiedCoordinates() {
QualifiedCoordinates c = new QualifiedCoordinates(_latitude,
_longitude, _altitude, _horAcc, _verAcc);
return c;
}
public float getSpeed() {
return _speed;
}
public String toString() {
String result = "Lat:" + String.valueOf(_latitude) + "|Lon:"
+ String.valueOf(_longitude) + "|Alt:"
+ String.valueOf(_altitude);
return result;
}
}
Then somewhere on the screen
MockupLocationProvider gpsProvider = new MockupLocationProvider();
GPSLocation loc = (GPSLocation)gpsProvider.getLocation(0);
add(new RichTextField(loc.toString()));
Outside GPS mockup
Another option is to generally mockup GPS signals.
Steps are:
configure device gps receiver for
bluetooth (for ex.)
setup some
opensource gps server on your desktop
to produce location data over
bluetooth
change configuration/code
of gps server to mockup location data
Other options
There is a possibility to uncontrolled change of location gps data by shielding gps receiver with some radio-material (like alluminium foil or so) :)

How to show our own icon in BlackBerry Map?

I want to know how to use our own logo to show the particular place in BBMap? Can anyone knows how to do this ?
BlackBerry Map
It's not possible in Blackberry Map to show custom icon for POI.
Things you can include in Location on Blackberry Map:
The latitude of the location * 100,000. South is negative.
The longitude of the location * 100,000. West is negative.
The label to be displayed beside the location.
The description displayed when the BlackBerry smartphone user selects
details.
Zoom level from 0 to MAX_ZOOM.
Address
City
Province or state
Country
Postal code
Phone
Fax
URL
Email address
Category
Rating information between 0 and 5
See What Is - BlackBerry Maps Location Document Format
Also see How To - Invoke BlackBerry Maps
Using MapField
As an alternative you can try MapField + manager/screen paint override.
Custom extension for MapField:
class CustomMapField extends MapField {
Bitmap mIcon;
XYRect mDest;
public void moveTo(Coordinates coordinates) {
super.moveTo(coordinates);
mDest = null;
}
protected void paint(Graphics graphics) {
super.paint(graphics);
if (null != mIcon) {
if (null == mDest) {
XYPoint fieldOut = new XYPoint();
convertWorldToField(getCoordinates(), fieldOut);
int imgW = mIcon.getWidth();
int imgH = mIcon.getHeight();
mDest = new XYRect(fieldOut.x - imgW / 2,
fieldOut.y - imgH, imgW, imgH);
}
graphics.drawBitmap(mDest, mIcon, 0, 0);
}
}
}
Example of use:
class Scr extends MainScreen {
CustomMapField mMapField;
Coordinates mCoordinates;
public Scr() {
LocationProvider provider = null;
Location location = null;
try {
provider = LocationProvider.getInstance(null);
} catch (LocationException e) {
e.printStackTrace();
}
try {
location = provider.getLocation(-1);
} catch (LocationException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
mCoordinates = location.getQualifiedCoordinates();
add(new LabelField("Latitude: "
+ String.valueOf(Coordinates.convert(
mCoordinates.getLatitude(),
Coordinates.DD_MM_SS))));
add(new LabelField("Longitude: "
+ String.valueOf(Coordinates.convert(
mCoordinates.getLongitude(),
Coordinates.DD_MM_SS))));
mMapField = new CustomMapField();
mMapField.mIcon = Bitmap.getBitmapResource("poi_icon.png");
mMapField.moveTo(mCoordinates);
add(mMapField);
}
}
See also
Using MapComponent in Blackberry
GPS and BlackBerry Maps Development Guide
Prepare GPS data
If it's real device, be sure GPS is available and turned on.
If it's simulator, then before you start program use simulator menu -> simulate -> GPS Location to set GPS data.
Other option is hardcode your own Coordinats and use them without GPS:
double latitude = 51.507778;
double longitude = -0.128056;
Coordinates mCoordinates = new Coordinates(latitude, longitude, 0);

Resources