GeoLoc.geoAddress
** Activity (main) Resume **
Error occurred on line: 33 (Main)
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at de.donmanfred.GeoLocatorwrapper.geoAddress(GeoLocatorwrapper.java:109)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:783)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:363)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:365)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
GeoLocation_Location(false, null, null, Unble to Trace your location)
b4a.example.main:_geolocation_location, [false, null, null, Unble to Trace your location]
Error occurred on line: 44 (Main)
java.lang.IllegalArgumentException: method b4a.example.main._geolocation_location argument 2 has type double, got null
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$2.run(BA.java:365)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
** Activity (main) Pause, UserClosed = true **
GeoLocation_Location(true, xx.25059298891574, yy.25199742987752, GPS_PROVIDER)
Make sure to call the method geoAddress only after you got a valid Location.java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Make sure to call the method geoAddress only after you got a valid Location.GeoLoc.geoAddress
Check v1.01. I´ve updated the lib in #1GeoLocation_Location(false, null, null, Unble to Trace your location)
I just tried to try your sample project.Make sure to call the method geoAddress only after you got a valid Location.
For any further issue: You should always start a new thread for your questions.
Sub GeoLocation_Location(success As Boolean, Lattitude As Double, Longitude As Double, info As String)
'GeoLocation_Location(true, xx.25059298891574, yy.25199742987752, GPS_PROVIDER)
Log($"GeoLocation_Location(${success}, ${Lattitude}, ${Longitude}, ${info})"$)
If success Then
GeoLoc.geoAddress
Log(GeoLoc.Address)
Log(GeoLoc.City)
Log(GeoLoc.Country)
Log(GeoLoc.KnownName)
Log(GeoLoc.PostalCode)
Log(GeoLoc.State)
End If
End Sub
public void GetLocation(BA ba) {
LocationManager locationManager = (LocationManager) ba.context.getSystemService(ba.context.LOCATION_SERVICE);
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
// showSettingsAlert();
//Toast.makeText(context, "Permission Denied", Toast.LENGTH_SHORT).show();
String info = "Permission Denied";
ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(false),null,null,info});
} else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Location location1 = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location location2 = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (location != null) {
double latti = location.getLatitude();
double longi = location.getLongitude();
lattitude = latti;
longitude = longi;
fromMockProvider = location.isFromMockProvider();
String info = "NETWORK_PROVIDER";
ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(true),lattitude,longitude, info, fromMockProvider});
} else if (location1 != null) {
double latti = location1.getLatitude();
double longi = location1.getLongitude();
lattitude = latti;
longitude = longi;
String info = "GPS_PROVIDER";
fromMockProvider = location1.isFromMockProvider();
ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(true),lattitude,longitude, info, fromMockProvider});
} else if (location2 != null) {
double latti = location2.getLatitude();
double longi = location2.getLongitude();
lattitude = latti;
longitude = longi;
fromMockProvider = location2.isFromMockProvider();
String info = "PASSIVE_PROVIDER";
ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(true),lattitude,longitude, info, fromMockProvider});
} else {
//Toast.makeText(context, "Unble to Trace your location", Toast.LENGTH_SHORT).show();
double value = 0;
fromMockProvider = false;
String info = "Unble to Trace your location";
ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(false),value,value, info, fromMockProvider});
}
}
}
You can call the method to get the location. It checks different providers and returns the one with a result.
I don´t know if there is something to FORCE a faster result.B4X:public void GetLocation(BA ba) { LocationManager locationManager = (LocationManager) ba.context.getSystemService(ba.context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { // showSettingsAlert(); //Toast.makeText(context, "Permission Denied", Toast.LENGTH_SHORT).show(); String info = "Permission Denied"; ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(false),null,null,info}); } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Location location1 = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location location2 = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); if (location != null) { double latti = location.getLatitude(); double longi = location.getLongitude(); lattitude = latti; longitude = longi; fromMockProvider = location.isFromMockProvider(); String info = "NETWORK_PROVIDER"; ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(true),lattitude,longitude, info, fromMockProvider}); } else if (location1 != null) { double latti = location1.getLatitude(); double longi = location1.getLongitude(); lattitude = latti; longitude = longi; String info = "GPS_PROVIDER"; fromMockProvider = location1.isFromMockProvider(); ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(true),lattitude,longitude, info, fromMockProvider}); } else if (location2 != null) { double latti = location2.getLatitude(); double longi = location2.getLongitude(); lattitude = latti; longitude = longi; fromMockProvider = location2.isFromMockProvider(); String info = "PASSIVE_PROVIDER"; ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(true),lattitude,longitude, info, fromMockProvider}); } else { //Toast.makeText(context, "Unble to Trace your location", Toast.LENGTH_SHORT).show(); double value = 0; fromMockProvider = false; String info = "Unble to Trace your location"; ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_location", true, new Object[] {Boolean.valueOf(false),value,value, info, fromMockProvider}); } } }
What does your sub looks like? It should be something like this:I apologize
I found an error like this in the log editor
is there anything that needs to be corrected?
Sub GeoLocation_Location(success As Boolean, Lattitude As Double, Longitude As Double, info As String)
'Something
Ens Sub
How call this code from b4a ?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?