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
Highlighted
Contributor
Posts: 40
Registered: ‎06-25-2012
My Device: BlackBerry Curver 9300
My Carrier: Etisalat

BlackBerry showMap when coordinates are 0.0, 0.0

Hi,

 

I am trying to check the text on the latitude and longitude Label Field and only if it is different from "0.0" and is not null, I want the user to be able to see the map. This is the code I am using on click of a button to show map:

 

public void showMap() {
String lti = lblLatitude.getText().toString();
String lngi = lblLongitude.getText().toString();
if (lti.length() == 0 || lngi.length()==0)
{
Dialog.alert("Location Unavailable - Cannot load map");
}
else if (lti=="0.0" || lngi=="0.0")
{
Dialog.alert("Location Unavailable - Cannot load map");
}
else if (lti!="0.0" || lti!="0.0")
{
Dialog.alert("Location from LabelField - "+lti+"-----"+lngi);
//MapScreen ms = new MapScreen();
MapScreen.getLatitude(lti);
MapScreen.getLongitude(lngi);
UiApplication.getUiApplication().pushScreen(new MapScreen());
}
}

 

However, even though the latitude and longitude are 0.0, it does not go through the if statement and opens the map page. Can anybody help what am I doing wrong here?

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BlackBerry showMap when coordinates are 0.0, 0.0

object (string) comparison is done using equals, with == you check on object identity.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: BlackBerry showMap when coordinates are 0.0, 0.0

Below is some code that will invoke BB Maps with the selected lat and long.

 

Instead of checking the String, one thing I would suggest is that you need to treat these values as numeric, so I would try to convert the input values to double, using something like

 

double mapLat = Double.parseDouble(lblLatitude.getText());

 

When you have numeric values, then comparing them to 0 is easy.

 

And if you put the parseDouble in a try, then the catch will get used if there is a format error in the input field (perhaps two full stops or similar) and you can tell the user.

 

Anyway, here is some code....

 

            MapView mapView = new MapView();
            int latInt = (int) (mapLat * 100000f);
            int longInt = (int) (mapLong * 100000f);
            mapView.setLatitude(latInt);
            mapView.setLongitude(longInt);
            mapView.setZoom(1);
            MapsArguments mapsArgs = new MapsArguments(mapView);
            Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, mapsArgs);