B4A Library GeoLocation

This is Library which is based on the code from this Github project.

GeoLocation
...|https://www.b4x.com
Author: DonManfred
Version: 1.1
  • GeoLocator
    • Events:
      • Location (success As Boolean, Lattitude As Double, Longitude As Double)
    • Functions:
      • geoAddress
      • GetLocation
      • Initialize (EventName As String)
    • Properties:
      • Address As String [read only]
      • City As String [read only]
      • Country As String [read only]
      • KnownName As String [read only]
      • Lattitude As Double [read only]
      • Longitude As Double [read only]
      • PostalCode As String [read only]
      • State As String [read only]

If get the Location from the System. It result in using th GPS Provider, Network Provider or PASSIVE_PROVIDER. In the resultevent you get info from which Provider the Location is from.
 

Attachments

  • GeoLocationV1.01.zip
    3 KB · Views: 572
  • GeoLocationV1.11.zip
    3.4 KB · Views: 754
  • GeoLocEx.zip
    9.3 KB · Views: 456
Last edited:

JohnC

Expert
Licensed User
@DonManfred,

Any chance you can update your sample app in OP to include these changes:

1) To set the event signature properly.
B4X:
Sub GeoLocation_Location(success As Boolean, Lattitude As Double, Longitude As Double, info As String, isMockLocation As Boolean)
    Log($"GeoLocation_Location(${success}, ${Lattitude}, ${Longitude}, ${info}, ${isMockLocation})"$)
End Sub

2) Remove these lines from the Activity_Create sub (and move them to sub #3 below) because it will crash trying to do geoAddress if GetLocation failed (or if the geolocation event didn't fire yet):
B4X:
GeoLoc.geoAddress
Log(GeoLoc.Address)
Log(GeoLoc.City)
Log(GeoLoc.Country)
Log(GeoLoc.KnownName)
Log(GeoLoc.PostalCode)
Log(GeoLoc.State)

3) And as in Post #8 to fix the crashing bug if GetLocation failed (and to also make sure this event sub's signature matches):
B4X:
Sub GeoLocation_Location(success As Boolean, Lattitude As Double, Longitude As Double, info As String, isMockLocation As Boolean)
    Log($"GeoLocation_Location(${success}, ${Lattitude}, ${Longitude}, ${info}, ${isMockLocation})"$)

    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

I ask because another user ran into these same issues and it would just save time all-around in the future:

 
Last edited:

DonManfred

Expert
Licensed User
I ask because another user ran into these same issues and it would just save time all-around in the future
1) done
2) done
3) done

Example updated
 

joaquinortiz

Active Member
Licensed User
This is Library which is based on the code from this Github project.

GeoLocation
...|https://www.b4x.com
Author: DonManfred
Version: 1.1
  • GeoLocator
    • Events:
      • Location (success As Boolean, Lattitude As Double, Longitude As Double)
    • Functions:
      • geoAddress
      • GetLocation
      • Initialize (EventName As String)
    • Properties:
      • Address As String [read only]
      • City As String [read only]
      • Country As String [read only]
      • KnownName As String [read only]
      • Lattitude As Double [read only]
      • Longitude As Double [read only]
      • PostalCode As String [read only]
      • State As String [read only]

If get the Location from the System. It result in using th GPS Provider, Network Provider or PASSIVE_PROVIDER. In the resultevent you get info from which Provider the Location is from.


Edit 08.04.2020:

Please change the Eventsignature in the Exmple to be this one:

B4X:
Sub GeoLocation_Location(success As Boolean, Lattitude As Double, Longitude As Double, info As String, isMockLocation As Boolean)
    Log($"GeoLocation_Location(${success}, ${Lattitude}, ${Longitude}, ${info}, ${isMockLocation})"$)
End Sub

Don, I have a question. The address(for example Zip Code) from where it's extracting this information?.

Also I realize, that in some cases, I run it, several times, and it doesn't bring the aproximatelly address, or in this case, the same Zip Code...for instance. I received at this momento my zipcode 64170....but after some time after (liek an 1 hour) I receive zipcode 64159.

I think that this could be for the GPS antenna, that it's not exactly. Or I'm wrong?
 

joaquinortiz

Active Member
Licensed User
From the Android Geocoder Object. Don´t know where GeoCoder get his infos from.

@DonManfred Thanks. I currently tested your sample, and I'm realize that it doesn't update the GPS location. I took your sample in 2 cellphones, and I drove my car, early 15mins ago, from my house to my work, its like 5kms long, and I test it the sample, and it doesn't refresh the address. To do the update, I have tu turno off "Location" antenna in both cells, kill the app, and start it again. And it shows me the current address (by the new gps location i have).

What do you think that could be happen?

PD. And some times it's not precise location.
 

oparra

Well-Known Member
Licensed User
@DonManfred Thanks. I currently tested your sample, and I'm realize that it doesn't update the GPS location. I took your sample in 2 cellphones, and I drove my car, early 15mins ago, from my house to my work, its like 5kms long, and I test it the sample, and it doesn't refresh the address. To do the update, I have tu turno off "Location" antenna in both cells, kill the app, and start it again. And it shows me the current address (by the new gps location i have).

What do you think that could be happen?

PD. And some times it's not precise location.

See:


 

oparra

Well-Known Member
Licensed User
better occupy services:



taking into account the policies of the service:

Daily quotas are not limited like google api
 

joaquinortiz

Active Member
Licensed User
See:



This is very surprising. But how do you think Uber or Didi manages to get a more accurate GPS position? Regardless of device

This is the million dollar question....hahahahahaha!!!!!
 

oparra

Well-Known Member
Licensed User
Uber and Didi use various location services.

check where is uber partner:

example:

etc.

and it will give you an idea.
 

oparra

Well-Known Member
Licensed User
As for the location of your phone, it is better to use:


and your geocoder service uses an external API

;););)
 

JohnC

Expert
Licensed User
@DonManfred Thanks. I currently tested your sample, and I'm realize that it doesn't update the GPS location. I took your sample in 2 cellphones, and I drove my car, early 15mins ago, from my house to my work, its like 5kms long, and I test it the sample, and it doesn't refresh the address. To do the update, I have tu turno off "Location" antenna in both cells, kill the app, and start it again. And it shows me the current address (by the new gps location i have).

What do you think that could be happen?

PD. And some times it's not precise location.

OK,

I don't have a lot of experience navigating a github project, so I can't seem to find any detailed info about the methods and events from the original developer.

Even though Don's info doesn't mention this, I do see a .GeoAddress2(Lattitude As Double, Longitude As Double) method using the object's intellisense.

.GeoAddress2(Lattitude As Double, Longitude As Double) - My guess is that this method provides a way to force the "GeoLocation_Location" event to trigger and return the address of the manually ("Mock") location provided via the lat and long parameters (instead of the device's detected GPS lat/long).

Also, you will notice that this lib doesn't really specify the accuracy of the lat and long it detected. It will specify the "service" that was used to obtain the lat/long (GPS/Wifi/Fused, etc) which can somewhat be used to know the accuracy of the lat/long, but I would not depend on it.

What I would do is use the more robust GPS object of Erel's example (https://www.b4x.com/android/forum/threads/background-location-tracking.99873/) and when that object detects a location, it will provide the accuracy of that location in meters.

So if my assumption on how the GeoAddress2 method works is correct, I would use the GPS object in Erel's example and wait for an acquisition that has an accuracy that meets my needs (like less then 25 meters), then I would use the lat/long reported from Erel's GPS object and call this lib's .GeoAddress2 method to force it to calculate the address based on the mock/manually provided via the lat/long of Erel's GPS object.

You will then notice that the GeoLocation_Location event has a "isMockLocation" parameter, I'm thinking that this value will be False for the times that this lib's geo library detects a location, and will be True when we force the lat/long location using the GeoAddress2 method. If all my assumptions are correct, then you would just need to make sure that this param is True before doing a .GeoAddress, so you'll know that the resulting street address is based on the manually provided lat/long (from Erel's GPS object) and not from this geo libs possibly inaccurate GPS location.
 
Last edited:

joaquinortiz

Active Member
Licensed User
As for the location of your phone, it is better to use:


and your geocoder service uses an external API

;););)

Great !, let me dive into this info and share my testings....to enrich this utilities.
 

joaquinortiz

Active Member
Licensed User
OK,

I don't have a lot of experience navigating a github project, so I can't seem to find any detailed info about the methods and events from the original developer.

Even though Don's info doesn't mention this, I do see a .GeoAddress2(Lattitude As Double, Longitude As Double) method using the object's intellisense.

.GeoAddress2(Lattitude As Double, Longitude As Double) - My guess is that this method provides a way to force the "GeoLocation_Location" event to trigger and return the address of the manually ("Mock") location provided via the lat and long parameters (instead of the device's detected GPS lat/long).

Also, you will notice that this lib doesn't really specify the accuracy of the lat and long it detected. It will specify the "service" that was used to obtain the lat/long (GPS/Wifi/Fused, etc) which can somewhat be used to know the accuracy of the lat/long, but I would not depend on it.

What I would do is use the more robust GPS object of Erel's example (https://www.b4x.com/android/forum/threads/background-location-tracking.99873/) and when that object detects a location, it will provide the accuracy of that location in meters.

So if my assumption on how the GeoAddress2 method works is correct, I would use the GPS object in Erel's example and wait for an acquisition that has an accuracy that meets my needs (like less then 25 meters), then I would use the lat/long reported from Erel's GPS object and call this lib's .GeoAddress2 method to force it to calculate the address based on the mock/manually provided via the lat/long of Erel's GPS object.

You will then notice that the GeoLocation_Location event has a "isMockLocation" parameter, I'm thinking that this value will be False for the times that this lib's geo library detects a location, and will be True when we force the lat/long location using the GeoAddress2 method. If all my assumptions are correct, then you would just need to make sure that this param is True before doing a .GeoAddress, so you'll know that the resulting street address is based on the manually provided lat/long (from Erel's GSP object) and not from this geo libs possibly inaccurate GPS location.

I tie with your logic!....let me dive into it and share the conclusions!!!...Thanks John for your involvement & time.
 

AdultWolf

New Member
Hi, Thanks for lib
just run and my error:
DonManfred

Error:
java.lang.Exception: Sub geolocation_location signature does not match expected signature.

    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)

    at anywheresoftware.b4a.BA$2.run(BA.java:387)

    at android.os.Handler.handleCallback(Handler.java:873)

    at android.os.Handler.dispatchMessage(Handler.java:99)

    at android.os.Looper.loop(Looper.java:201)

    at android.app.ActivityThread.main(ActivityThread.java:6861)

    at java.lang.reflect.Method.invoke(Native Method)

    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
 

DonManfred

Expert
Licensed User
Top