Android Question GMaps with FusedLocationProvider

stanks

Active Member
Licensed User
Longtime User
Hi

Following https://www.b4x.com/android/forum/threads/google-maps-with-fusedlocationprovider.83876/ tutorial, i tried to adapt it to my app.
GPS settings dialog should be opened from activity "Test" and not Main only when user taps on button for showing location on map. If we have that lat/lon in DB show it on the map. If we don't have that lat/lon in DB, call FLP, get lat/lon and show it on the map. User can use all other stuff in app without that GPS and FLP.
I don't have a problem with storing that values in DB, but logic with calling/showing GPS dialog to user and calling FLP. Where i put code which is in Main activity in sub Activity_Create? Should i change/adapt some other part of that code from that example or not?

Thanks
 

stanks

Active Member
Licensed User
Longtime User
well the prolem is that when i adapt (copy/paste) your example to my app, user has to enable GPS when app starts. but user can use my app without using GPS. GPS and FLP is necessary only when they want to see loc on map or when they want to get their current loc. so to avoid that starting GPS settings dialog from Main i have to put that code and start GPS settings dialog when user taps on button which will show loc on map and that is not Main activity.
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
i partially solved this by adding one boolean variable in second activity and pass true to third when user taps button but i still have issues (read not working as i expected)
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I fsoleved, please, do not forget to publish any result codes...
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
Not sure that I understand the question.

These lines set the map location source:
B4X:
Dim jo As JavaObject = gmap
jo.RunMethod("setLocationSource", Array(Starter.LocationSource))

You can call it from wherever you like.
How? object is gmap. i don't have gmap in every activity...it is in only one activity. so from 1st i should call FLP and get loc or take loc from DB and call second activity to show FLP or DB location. so how to call it from wherever?

thanks
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
if i leave that code in starter, when i start my app i get world map activity. this is not what i wanted. to be easier to understand, can you change your example and add one button on which when user tap it will open world map with that hardcoded location from your example and 2nd button when tapped will start FLP, get current location and show it on world map. this is what i am trying to achieve.

thanks for reading
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
because it is faster? if i understand you second question it is because destination point doesn't have lat/lon when my app is started and because for some destination points i don't have full address meaning no address with number so i get point in the center of the address (street long 5km will have point in the middle of it and not on exact point what i want)
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
here it is. i tried but i don't know how to do it. i moved all code from starter to another service. if code stay in starter service every time i start app first map is showed and not main activity which now has 1 button. if user taps on that button service should be called, flp should get current loc and show it on map. if service does not work it should show 30,10 location marker.
 

Attachments

  • flp.zip
    11.5 KB · Views: 136
Upvote 0

stanks

Active Member
Licensed User
Longtime User
ok. so here it is. working example (for now) with current location from FLP and hardcoded value (this value was not tested but i hope that it works ok too). i used FLP lib and not example from Erel. i simply don't know how to do that with his example. only thing you need to change is GEO API KEY and run test.
 

Attachments

  • flp.zip
    13 KB · Views: 160
Upvote 0

stanks

Active Member
Licensed User
Longtime User
is it possible to adapt your example to something like that? (less code and much more readable)
 
Upvote 0
Top