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
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

"get My Location"

[ Edited ]

hi everyone

I am currently trying to do the following:

- get the gps mode that is available for current handheld.

- get the current GPS co ordinates of the handheld location.

- set the co ordinates of the map

- view map with the set location.

 

unfortunately I keep getting the following error: " Error in location :java.lang.NumberFormatException:"

 

I used the following code to get the available gps mode and to detect the coordinates:

 

public void GetCurrentLocation(){
BlackBerryCriteria blackBerryCriteria = null;
BlackBerryLocation blackBerryLocation = null;
BlackBerryLocationProvider blackBerryLocationProvider = null;
double lat = 0.0;
double lng = 0.0;
blackBerryCriteria = new BlackBerryCriteria();
if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CELLSITE)) {
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CELLSITE);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CDMA_MS_BASED)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CDMA_MS_BASED);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CDMA_MS_ASSIST)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CDMA_MS_ASSIST);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CDMA_DATA_OPTIMAL)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CDMA_DATA_OPTIMAL);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CDMA_ACCURACY_OPTIMAL)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CDMA_ACCURACY_OPTIMAL);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_BT)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_BT);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_ASSIST);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_AUTONOMOUS);
}else{
blackBerryCriteria.setCostAllowed(true);
blackBerryCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
}try{
blackBerryLocationProvider = (BlackBerryLocationProvider) BlackBerryLocationProvider.getInstance(blackBerryCriteria);
blackBerryLocation = (BlackBerryLocation) blackBerryLocationProvider.getLocation(60);
QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates();
lat = qualifiedCoordinates.getLatitude();
lng = qualifiedCoordinates.getLongitude();

String latString = Double.toString(lat);
String lngstring = Double.toString(lng);
String Test2=".";
String Test3="";
FinalSringLatetude =replace(latString,Test2,Test3);
FinalSringLongdetude =replace(lngstring,Test2,Test3);
intLat = Integer.valueOf(FinalSringLatetude).intValue();
iintLng = Integer.valueOf(FinalSringLongdetude).intValue();

 

}catch(Exception e){
System.out.println("Error in location :"+e.toString());
System.out.println("Error in location :"+e.getMessage());
}
}

 

I followed the steps in this link to set the current coordinates of the map and view the map.

http://docs.blackberry.com/en/developers/deliverables/8106/BB_Maps_display_a_custom_map_view_467975_...

 

i removed the ". " out of the coordinates because i thought that it might cause the problem( if you look at the link you will see that that the "." has also been removed from the coordinates), but I am Still getting the same error.

 

Please can some one help me I have been stuck with this problem for way too long now.

 

Thank you

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: "get My Location"

[ Edited ]

I have even done the following:

 

mapView.setLatitude((int) (intLat * 100000));
 mapView.setLongitude((int) (iintLng* 100000));

and

 

mapView.setLatitude((int) (intLat /100000));
 mapView.setLongitude((int) (iintLng/100000));

 

What Am I doing wrong??

Developer
Posts: 52
Registered: ‎11-24-2011
My Device: Bold 9930
My Carrier: Rogers

Re: "get My Location"

This is regular debugging routine - first, you have to find which line throws that exception.

As far as I can see, it can be one of:

intLat = Integer.valueOf(FinalSringLatetude).intValue();
intLng = Integer.valueOf(FinalSringLongdetude).intValue();

Next, in your first source I do not see these lines:

mapView.setLatitude((int) (intLat * 100000));
mapView.setLongitude((int) (iintLng* 100000));

So which line is the problem?

If you cannot debug just add println() before and after line under the question.

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: "get My Location"

Hi there.

 

Thank you for responding...

 

}try{
blackBerryLocationProvider = (BlackBerryLocationProvider) BlackBerryLocationProvider.getInstance(blackBerryCriteria);
blackBerryLocation = (BlackBerryLocation) blackBerryLocationProvider.getLocation(60);
QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates();
lat = qualifiedCoordinates.getLatitude();
System.out.println("1= "+lat);
lng = qualifiedCoordinates.getLongitude();
System.out.println("2= "+lng);
latString = Double.toString(lat);
System.out.println("3="+latString);
lngstring = Double.toString(lng);
System.out.println("4="+lngstring);
String Test2=".";
String Test3="";
FinalSringLatetude =replace(latString,Test2,Test3);
System.out.println("5="+FinalSringLatetude);
FinalSringLongdetude =replace(lngstring,Test2,Test3);
System.out.println("6="+FinalSringLongdetude);
intLat = Integer.valueOf(FinalSringLatetude).intValue();
System.out.println("7="+intLat);
iintLng = Integer.valueOf(FinalSringLongdetude).intValue();
System.out.println("7="+iintLng);



}catch(Exception e){
System.out.println("Error in location :"+e.toString());
System.out.println("Error in location :"+e.getMessage());
}
}
public void GoToMapWithGPSCoOrd(){
MapView mapView = new MapView();
mapView.setLatitude((int) (intLat / 100000));

mapView.setLongitude((int) (iintLng/100000));

mapView.setZoom(10);
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(mapView));
}

 

My Error occures at the Latitude field i do have the gollowing in my code:

mapView.setLatitude((int) (intLat * 100000));
 mapView.setLongitude((int) (iintLng*100000));

(check the link)

 

The problem is the Latitude. 

 

quick question :

when reading the coordinates to the "mapview.set.." must there be no " . " 

 

Developer
Posts: 52
Registered: ‎11-24-2011
My Device: Bold 9930
My Carrier: Rogers

Re: "get My Location"

First, no need in full source just suspicious lines.

Next, terminology should be correct: what is “Latitude field”?

Same for “reading the coordinates to..”, is it “passing parameter to ..” ?

Now, what is the value of ‘intLat’?

I mean, max integer value in JAVA is 2147483647.

Last, what '.' your are talking about - MapView.setLatitude() accepts only integer value?!

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: "get My Location"

Latitude field is:
double lat = qualifiedCoordinates.getLatitude();
what I am doing is I am taking the double converting it into a string Removing the " . " in the coordinate as the "maview.setlat.." only takes int's the value of int lat = 2601519 (without ".")
int this example @ the link above they dont mention anythin about adding *100000 when setting the lat/ long on the map but either way it doesnt work
Developer
Posts: 52
Registered: ‎11-24-2011
My Device: Bold 9930
My Carrier: Rogers

Re: "get My Location"

So, 2601519 * 100000 = 260,151,900,000 (do not look at commas) is a bit longer than 2,147,483,647 !

Are you saying that passing just 2601519 to setLatitude() throws that exception?

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: "get My Location"

yes, as far as i understand, why does it have to be * 100 000?

Developer
Posts: 52
Registered: ‎11-24-2011
My Device: Bold 9930
My Carrier: Rogers

Re: "get My Location"

From docs "The latitude (100,000 times the value specified by WGS84)"

WGS84 range is in degrees. For example, New-York - 40.7142° N, 74.0064° W