B4A Library Mock-LocationProvider Lib

Hi all,

I've written a small mock-locationProvider-library for B4A in java.

In this case I have to say thank You for all mates, who described the how to build a a4b-lib! - It was my second try of making an own lib in eclipse...
... and had great succes:)

If anyone is interested in further informations about my lib, let me know it.


regards

bitstra

Edit: uploaded library (1.0) with demo project :)

The demo code is well commented.



The moclocationprovider - library devlivers 3 public void() out of java-lib.
1. enableMockProvider(...)
2. publishMockLocation(............)
3. disableMockLocation(...)

If u test it, have a look to all comments in the sample procet code, about using the lib.
Also have look to code structure in ServiceModule (Timer_Tick), for calling publishMockLocation().

After using the sample you have to reboot your device, because my lib functions use the system GPS_PROVIDER name by android os.
!!!Without reboot the buildin gps-hardware can't deliver location data to the system!!!


bye

bitstra
 

Attachments

  • MLPservice.zip
    30.9 KB · Views: 1,103
Last edited:

schimanski

Well-Known Member
Licensed User
Longtime User
Is there a simple way to convert the coordinates from the normal b4a-format to the mock_location-format? I have tried some things, but the mock_location provider ignores all my tested formats. Only a manually string like the example does work....

Thanks for help...
 

schimanski

Well-Known Member
Licensed User
Longtime User
For example:

Latitude: 5134.5667
Longitude: 006.4574

:confused:

Gesendet von meinem XT910 mit Tapatalk 2
 

schimanski

Well-Known Member
Licensed User
Longtime User
Hmmm, I have tried serveral things to change the normal decimal-coordinates to the following format, which I have to use for the mock-location provider, but I think, that are not decimal_degrees:confused:

B4X:
latitude="5234.1421"        'lat. as decimal_degrees
longitude="01311.7996"        'long. as decimal_degrees

Has someone a sub to change the normal decimal-degree like 50.7478484 to the format above?

Thanks for help...
 

bitstra

Member
Licensed User
Longtime User
Yes! here you go:

Here's how you convert latitude & longitude obtained from NMEA's GPGGA to decimal:

-------------/NMEA--------------/--------Decimal
latitude----/0302.78469 --------/-------03 + (02.78469/60) = 3.046412
longitude--/10141.82531-------/-------101 + 41.82531/60) = 101.6971


Notice that for latitude of 0302.78469,

03 ==> degress. counted as is

02.78469 ==> minutes. divide by 60 before adding to degrees above


Hence, the decimal equivalent is:
03 + (02.78469/60) = 3.046412



This way I convert the coordinates from NMEA Strings to dercimal in my GPS projects...

good luck

bitstra

Hmmm, I have tried serveral things to change the normal decimal-coordinates to the following format, which I have to use for the mock-location provider, but I think, that are not decimal_degrees:confused:

B4X:
latitude="5234.1421"        'lat. as decimal_degrees
longitude="01311.7996"        'long. as decimal_degrees

Has someone a sub to change the normal decimal-degree like 50.7478484 to the format above?

Thanks for help...
 
Last edited:

schimanski

Well-Known Member
Licensed User
Longtime User
I forgot the divide by 60 before adding.:sign0148:

It works....:sign0060:
 

Quaki

Member
Licensed User
Longtime User
Hi this library works great :) but is it posssible to add one more thing to this library ? The number of satelites ? It could be usefuul
Quaki
 

entolium

Member
Licensed User
Longtime User
Hi this library works great :) but is it posssible to add one more thing to this library ? The number of satelites ? It could be usefuul
Quaki

I'm in agree with you. This is a fantastic library and I'm using in my project, but I want to add more parameters like speed and satelites :(
 

Andrei E

Member
Licensed User
Longtime User
How to convert gps location into the mock?
B4X:
Sub GPSService_LocationChanged (Location1 As Location)
    Latitude = Location1.Latitude             ' 52.12345678
    Longitude  = Location1.Longitude        ' 25.12345678
End Sub
My issue is wrong format. The mock can't accept my GPS locations
 

Andrei E

Member
Licensed User
Longtime User
or how to convert GPS values into the this mock?
example (18e Avenue lat: 45.562708 lon: -73.5948923)
 

carlos7000

Well-Known Member
Licensed User
Longtime User
Hello

Try to use the example but when trying to execute the program, an error is reported that informs:


java.lang.SecurityException: de.esolutions4you.mlpdemo from uid 10187 not allowed to perform MOCK_LOCATION
.
.
.
java.lang.RuntimeException: Unable to stop service de.esolutions4you.mlpdemo.mlpservice@dfba757: java.lang.RuntimeException: java.lang.SecurityException: de.esolutions4you.mlpdemo from uid 10187 not allowed to perform MOCK_LOCATION
.
.
.Caused by: java.lang.RuntimeException: java.lang.SecurityException: de.esolutions4you.mlpdemo from uid 10187 not allowed to perform MOCK_LOCATION
.
.
.
Caused by: java.lang.SecurityException: de.esolutions4you.mlpdemo from uid 10187 not allowed to perform MOCK_LOCATION
 

DonManfred

Expert
Licensed User
Longtime User

Fusseldieb

Active Member
Licensed User
Longtime User
Hello

Try to use the example but when trying to execute the program, an error is reported that informs:
"not allowed to perform MOCK_LOCATION"

- Are you sure that the DEVELOPER options are enabled on your device?
- Are you sure that in the developer options "Allow mock locations" is ENABLED?
- Are you sure that you've set the permission in your app adding
B4X:
AddPermission(android.permission.ACCESS_MOCK_LOCATION)
inside the manifest editor?
- Have you set the target API to 16 (or below)? This is required by this library, as it's getting deprecated. Don't use it in production, as Google will force API 26 very very soon!
 
Last edited:

carlos7000

Well-Known Member
Licensed User
Longtime User
- Are you sure that the DEVELOPER options are enabled on your device?
- Are you sure that in the developer options "Allow mock locations" is ENABLED?
- Are you sure that you've set the permission in your app adding
- Add: AddPermission(android.permission.ACCESS_MOCK_LOCATION)
- Have you set the target API to 16 (or below)? This is required by this library, as it's getting deprecated. Don't use it in production, as Google will force API 26 very very soon![/QUOTE]

Mode Developer: OK.
Allow mock locations: ¿?
Set the permission in your app adding: ¿?
set the target API to 16: OK

My manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddPermission(android.permission.ACCESS_MOCK_LOCATION)
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
 
Top