Android Tutorial Google Maps with FusedLocationProvider

Google Maps uses the GPS as its location provider. It will not show the current location if GPS is disabled.
It is possible to switch to a custom location provider.

For example, here is me traveling in Antarctica:

SS-2017-09-13_10.30.25.png


The attached example uses FusedLocationProvider to inject the location.

The steps to create a custom location source are:

1. Create the LocationSource object with JavaObject.
2. Handle the LocationSource_Event. It will raise when the source is activated.
3. Set the map source by calling setLocationSource.
4. Call LocationChangedListener.onLocationChanged method to inject locations.

These steps are done in the starter service.


You need to open the manifest editor and set your api key.
 

Attachments

  • GoogleMapsWithFusedLocationProvider.zip
    10.4 KB · Views: 1,246

BillMeyer

Well-Known Member
Licensed User
Longtime User
@Erel - and you are doing all this from Antarctica - impressive - Thank You !! - Just don't freeze - we need you !!
 

peacemaker

Expert
Licensed User
Longtime User
Thanks, Erel !
So, if GPS is disabled - it's needed to set another LocationSource with PRIORITY_BALANCED_POWER_ACCURACY ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Tried. And do not understand now what we can get from Google Map - gmap.MyLocation.IsInitialized is anyway false.
FLP_LocationChanged occurs only if GPS is allowed.
Map is visible, but no current position anyway :(

How to setup the code sample to be in Antarctica ? :)
 
Last edited:

EduardoElias

Well-Known Member
Licensed User
Longtime User
based on this, can i avoid to have the COARSE_LOCATION and FINE_LOCATION in manifest?

today I have
RemovePermission(android.permission.ACCESS_COARSE_LOCATION)
RemovePermission(android.permission.ACCESS_FINE_LOCATION)

on manifest, the reason is that my app will be incompatible with some tablet if I declare this permission.

However I need to use google maps, i was using it by browser and was somewhat working (some old tablets does not work properly)

I wanted to switch to the google maps views. I have the coordinates based on ZIPCODE what is all that I need from start and target and what to use this on the map, eventually even make the route.

Is this FusedLocation the way to go?
 

tomky

Active Member
Licensed User
Hi.

Why in this exercise, when you add the Sub Activity_Pause and you minimize the exercise, a dialog appears saying that the application has stopped?
And it appears in the log java.lang.Exception: Sub activity_pause signature does not match expected signature.

This happens on my emulator with several APIS, and on my Android device with API 17.

Thank you.
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hi.

Why in this exercise, when you add the Sub Activity_Pause and you minimize the exercise, a dialog appears saying that the application has stopped?
And it appears in the log java.lang.Exception: Sub activity_pause signature does not match expected signature.

This happens on my emulator with several APIS, and on my Android device with API 17.

Thank you.

That's probably because you didn't add UserClosed.
B4X:
Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

tomky

Active Member
Licensed User
Hi.

Another question.

How can this Erel exercise work on devices with Androis 6+ (API 23+) without resorting to the RuntimePermissions library and keeping the sdkversion tarjet in API 22?

Thank you.
 
Last edited:

tomky

Active Member
Licensed User
Thanks Erel.
Only I wanted to know if it is essential to use RuntimePermissions so that this exercise works on Android 6+ devices.
 
Top