Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Private NativeMe As JavaObject
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
NativeMe.InitializeContext
End If
Dim geolat As Double = 50.8248068
Dim geolon As Double = 6.4326403
Dim degrees As String = NativeMe.RunMethod("getFormattedLocationInDegree", Array As Object(geolat, geolon))
Log($"Degree = ${degrees}"$)
'Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
xui.MsgboxAsync("Hello world!", "B4X")
End Sub
#If JAVA
import android.location.Location;
public static String getFormattedLocationInDegree(double latitude, double longitude) {
try {
int latSeconds = (int) Math.round(latitude * 3600);
int latDegrees = latSeconds / 3600;
latSeconds = Math.abs(latSeconds % 3600);
int latMinutes = latSeconds / 60;
latSeconds %= 60;
int longSeconds = (int) Math.round(longitude * 3600);
int longDegrees = longSeconds / 3600;
longSeconds = Math.abs(longSeconds % 3600);
int longMinutes = longSeconds / 60;
longSeconds %= 60;
String latDegree = latDegrees >= 0 ? "N" : "S";
String lonDegrees = longDegrees >= 0 ? "E" : "W";
return Math.abs(latDegrees) + "°" + latMinutes + "'" + latSeconds
+ "\"" + latDegree +" "+ Math.abs(longDegrees) + "°" + longMinutes
+ "'" + longSeconds + "\"" + lonDegrees;
} catch (Exception e) {
return ""+ String.format("%8.5f", latitude) + " "
+ String.format("%8.5f", longitude) ;
}
}
public String convertLAT2degrees(double lat) {
String strLatitude = Location.convert(lat, Location.FORMAT_DEGREES);
return strLatitude;
}
public String convertLON2degrees(double lon) {
String strLongitude = Location.convert(lon, Location.FORMAT_DEGREES);
return strLongitude;
}
public String convertLAT2seconds(double lat, int decimalPlace) {
String strLatitude = Location.convert(lat, Location.FORMAT_SECONDS);
strLatitude = replaceDelimiters(strLatitude, decimalPlace);
strLatitude = strLatitude + " N";
return strLatitude;
}
public String convertLON2seconds(double lon, int decimalPlace) {
String strLongitude = Location.convert(lon, Location.FORMAT_SECONDS);
strLongitude = replaceDelimiters(strLongitude, decimalPlace);
strLongitude = strLongitude + " W";
return strLongitude;
}
public String convertLAT2minutes(double lat) {
String strLatitude = Location.convert(lat, Location.FORMAT_MINUTES);
return strLatitude;
}
public String convertLON2minutes(double lon) {
String strLongitude = Location.convert(lon, Location.FORMAT_MINUTES);
return strLongitude;
}
private static String replaceDelimiters(String str, int decimalPlace) {
str = str.replaceFirst(":", "°");
str = str.replaceFirst(":", "'");
int pointIndex = str.indexOf(".");
int endIndex = pointIndex + 1 + decimalPlace;
if(endIndex < str.length()) {
str = str.substring(0, endIndex);
}
str = str + "\"";
return str;
}
#End If