Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Member
njnjnj
Posts: 1
Registered: ‎07-09-2010
My Device: NA

GPS location issue for Black Berry Application

We have implemented GPS in our BlackBerry(BB) application to get the current location coordinates that we are using to get information like - location name, location zip code, etc.

 

 

 

To develop this, we followed the document provided by BlackBerry official website which is available right now at this location - http://docs.blackberry.com/en/developers/deliverables/11944/GPS_overview

_857606_11.jsp

 

 

 

It works fine when the device is in an area from where it can search satellites easily (say, outside a building and in an open space) but the problem starts when we use this inside a building and in this case, it is not able to fix the GPS and due to which we don't get location coordinates.

 

 

 

I have checked all the BlackBerry forums for this problem but I couldn't get any solution.

 

I have also increased the horizontal and vertical accuracy level to 2000 meters and with different Criteria for different modes other than a "null" Criteria but then also it didn't work.

 

 

 

Please check the different Criteria for different modes which I have

tested:

 

 

 

// CELLSITE

 

Criteria myCriteria = new Criteria();

 

myCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);

myCriteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);

myCriteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);

myCriteria.setCostAllowed(true);

  

 

// ASSIST

Criteria myCriteria = new Criteria();

myCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_MEDIUM);

myCriteria.setHorizontalAccuracy(500);

myCriteria.setVerticalAccuracy(500);

myCriteria.setCostAllowed(true);

  

 

// AUTONOMOUS

Criteria myCriteria = new Criteria();

myCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);

myCriteria.setHorizontalAccuracy(2000);

myCriteria.setVerticalAccuracy(2000);

myCriteria.setCostAllowed(false);

  

 

//any of the available location providers will be returned if myCriteria is null

 

Criteria myCriteria = null;

 

 

 

My question is, how is GoogleMaps application able to find the locations by using GPS inside a building? Is there any way in which we can also get the location coordinates by using GPS when we're inside a building?

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS location issue for Black Berry Application

Google doesn't just use GPS.  Google also have GPS located all the cell towers and so can map from these to your approximate location.  So if you are on wireless, Google will have a good chance of figuring out approximately where you are.

 

GPS on the other hand, has no chance. 

 

There are Threads on this forum that talk about how one might use Google or another provider to find this out for yourself based on your current tower. Have a search around. 

Regular Contributor
anawara
Posts: 64
Registered: ‎04-27-2010
My Device: Bold 9000

Re: GPS location issue for Black Berry Application

njnjnj,

 

I've been suffering from the same problem the past week and I've finally reached a solution. I use google's geolocation web service to retrieve location using cell ids. Its not very accurate but workable.

 

The webservice (http://www.google.com/loc/json) uses HTTP POST and takes a JSON string with the parameters required to triangulate the phone. To construct the JSON string you'll need the j2me version of the JSON library for java.

 

The following code constructs the json string that is required by the webservice (jsonString is of type JSONObject)

 

jsonString.put("version", "1.1.0");
jsonString.put("host", "maps.google.com");
int x = RadioInfo.getMCC(RadioInfo.getCurrentNetworkIndex());
jsonString.put("home_mobile_country_code", Integer.parseInt(Integer.toHexString(x)));
                
jsonString.put("home_mobile_network_code", RadioInfo.getMNC(RadioInfo.getCurrentNetworkIndex()));
int radio = RadioInfo.getNetworkType();
                
jsonString.put("radio_type","gsm");
jsonString.put("carrier", RadioInfo.getCurrentNetworkName());
jsonString.put("request_address", true);
jsonString.put("address_language", "en_GB");
                
CellTower cellInfo = new CellTower(Integer.toHexString(x),                                                  GPRSInfo.getCellInfo().getLAC(),                                                   GPRSInfo.getCellInfo().getRSSI(), GPRSInfo.getCellInfo().getCellId(),                                                    0,RadioInfo.getMNC(RadioInfo.getCurrentNetworkIndex()));
Hashtable map = new Hashtable();
map.put("mobile_country_code",new Integer(Integer.parseInt(cellInfo.mobileCountryCode)));
map.put("location_area_code", new Integer(cellInfo.locationAreaCode));
map.put("signal_strength", new Integer(cellInfo.signalStrength));
map.put("cell_id", new Integer(cellInfo.cellID));
map.put("age", new Integer(0));
map.put("mobile_network_code",new Integer(cellInfo.mobileNetworkCode));
                
JSONArray array = new JSONArray();
array.put(0,map);
                
jsonString.put("cell_towers",array)

 

CellTower is an inner class with the following structure

 

private class CellTower{
        public String mobileCountryCode;
        public int locationAreaCode;
        public int signalStrength;
        public int cellID;
        public int age;
        public int mobileNetworkCode;
        
        private CellTower(String mcc, int lac, int ss, int ci, int a, int mnc){
            mobileCountryCode = mcc;
            locationAreaCode = lac;
            signalStrength = ss;
            cellID = ci;
            age = a;
            mobileNetworkCode = mnc;
        }
    }

 

Once you construct the JSON string above you just POST it to the webservice.

 

To retrieve longitude and latitude from the response string simply parse it into a JSONObject using the following code:

 

try{
                JSONObject ob = new JSONObject(response);
                JSONObject ob2 = (JSONObject) ob.get("location");
                
                Double longitude = (Double)ob2.get("longitude");
                Double latitude = (Double)ob2.get("latitude");
                               
                application.geoLocatorFinished(longitude.doubleValue(),latitude.doubleValue());
            
            }catch(JSONException exp){
                application.log("JSON String error "+response);
            }

 

The application.geoLocatorFinished() method is what I used as a callback method to my controller object to proceed with processing the longitude and latitude.

 

Well hope this helps you!

 

If you need anything else please let me know!

 

Good luck! 

Nawara

 

 

Developer
mohitsharma
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: GPS location issue for Black Berry Application

hi nawara,

 

Can u post a link for the specification of this Google Maps API?

 

 

thanks.

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Regular Contributor
anawara
Posts: 64
Registered: ‎04-27-2010
My Device: Bold 9000

Re: GPS location issue for Black Berry Application

Hi mohitsharma,

 

The specs could be found here http://code.google.com/p/gears/wiki/GeolocationAPI

 

Developer
mohitsharma
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: GPS location issue for Black Berry Application

hey,

 

which JSON library you are usaing?

 

thanks.

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Regular Contributor
anawara
Posts: 64
Registered: ‎04-27-2010
My Device: Bold 9000

Re: GPS location issue for Black Berry Application

Hi

 

I'm using the json library available for j2me. It took me a while to find it and finally came across the source code.. I've uploaded a rar file containing the source code files to this link for you to download

 

You can either include these source files in your project or create another project that has them and compile it as a Library. Let me know if you need any help using it

 

 

Developer
mohitsharma
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: GPS location issue for Black Berry Application

hey thanks.

was looking for the same but couldn't find it.

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Regular Contributor
anawara
Posts: 64
Registered: ‎04-27-2010
My Device: Bold 9000

Re: GPS location issue for Black Berry Application

Anytime man..

 

Let me know how things go and if you need anymore help please tell me

 

Good luck

Regular Contributor
dan12345
Posts: 64
Registered: ‎02-03-2010
My Device: Bold

Re: GPS location issue for Black Berry Application

works!

 

Thanks alot for this thread