Android Question Sending GPS data to client via cellular

maleche

Active Member
Licensed User
Longtime User
Licensed User
Anyway to use client/server method to send GPS lat/lon from one client (cell phone) to a server cell phone to pass information? I want to make an app that consolidates our Emergency Response and Search and Rescue team's positions and emergency recourses locations.
Basically, each Emergency Response member's Lat/Lon is transmitted via cellular to a 'master' cell phone which plots on Google Map everyone's position every 5 minutes.
This would really help out!
best,
 

maleche

Active Member
Licensed User
Longtime User
In the field there is cell service.
We don't have access to use a dedicated server so i thought thar using B4A client/server may work.
I'm open to ideas!
Thank you!
 
Upvote 0

An Schi

Well-Known Member
Licensed User
I'm open to ideas!

Not thought to the end, just some ideas to avoid the smartphone master:
- use a free webspace and every phone uploads/downloads .txt files with the latlong via ftp
- use FCM to push the latlong to other phones
- use google spreadsheet as a "database" for the latlong
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
As An Shi said, FCM might be a good solution for getting the position data to the "master" device. You can either use a topic that the device subscribes to or you can send directly to the device using a token then plot the positions on Google Maps.

This is actually very similar to a project I'm currently working on.

- Colin.
 
Upvote 0

An Schi

Well-Known Member
Licensed User
It is an option....
....but i would not send data into one direction. I would send the latlong everywhere and then all the devices do their own processing with it. Beeing decentral seems the better way for me working in the field with search and rescue.
 
Upvote 0

maleche

Active Member
Licensed User
Longtime User
Interesting reading on firebase!
Sounds promising but i will have to learn the schema to pass lat/lon and message for all to receive then plot everyone's GPS position on Google Map on each phone.
The sms example might work as well!
I will look for any GPS using firebase examples.
That everyone! You are helping to save a life one day!
Best
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
You cannot make an incoming connection over the cellular network.

Are you referring to FCM Erel? I just ran a test on the FCM based app I'm developing & FCM messages were received fine on a phone with WiFi turned off (so via the cell network).

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
One interesting point worth considering: I read an evaluation paper on Google Cloud Messaging - (I have read elsewhere that FCM is just a re-branded GCM - I don't know whether that's true or not because I don't have any first hand experience with GCM) - titled "Google Cloud Messaging (GCM): An Evaluation". The conclusion that the study came to was:

"[...]However, GCM is not a good fit for the applications where the broadcasting is mission critical, i.e. the message arrival to all client devices is vital, such as emergency alert services, fire alert systems, instant messaging apps, disaster alert services etc.[...]"

If you want to read the paper in its entirety, you can find it here.

- Colin.
 
Upvote 0

maleche

Active Member
Licensed User
Longtime User
just finished reading the GCM evaluation report. VERY well constructed.
I do however, challenge one point in the dissertation; specifically, Turkish cellular infrastructure. I was stationed in Turkey and know the terrain/topography will interfere with cell transmission. There is little regulation regarding building height (new construction) when considering existing towers and line-of-sight placement.
That being said, I would like to try your suggestion Computersmith64! If you have code to share I would love to learn from it and try a base-line test!
Best,
-Doyle
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
just finished reading the GCM evaluation report. VERY well constructed.
I do however, challenge one point in the dissertation; specifically, Turkish cellular infrastructure. I was stationed in Turkey and know the terrain/topography will interfere with cell transmission. There is little regulation regarding building height (new construction) when considering existing towers and line-of-sight placement.
That being said, I would like to try your suggestion Computersmith64! If you have code to share I would love to learn from it and try a base-line test!
Best,
-Doyle
I didn't read the whole thing, but from the conclusion I got the impression that the non-delivery of messages is not necessarily related only to network stability. I have read other comments online that suggest there is an inherent reliability issue with GCM message delivery.

If I was using FCM / Google Maps for an app like this (based on your description in the original post), I would make the app user-definable as either a client or server. In your case (& to be consistent with the way FCM works), you would have multiple "servers" (the guys out in the field) & 1 "client" (the master app). Both variations would have Maps running & the servers would be sending their current position to a FCM topic that the client is subscribed to. When a message arrives, the client would plot that position on the map, along with any other information contained in the message (like the crew member's name). You would configure the app to send a message every (x) seconds (using a timer) or based on distance moved (calculated from GPS positions).

There is a very good tutorial on how to implement Google Maps in your app here -> Google Maps. This is what I used to get me started.

To construct an FCM message with the relevant data you could do something like this (replace gmap with whatever your GoogleMap object is declared as):
B4X:
Private Sub sendLocationMessage
    Private Job As HttpJob
    Private jg As JSONGenerator
    Private m As Map = CreateMap("to": $"/topics/fieldpositions"$)
    Private data As Map = CreateMap("sendername": "Dave", "lat": gmap.MyLocation.Latitude, "lon": gmap.MyLocation.Longitude)
    m.Put("data": data)
   
    Job.Initialize("fcm", Me)
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json")
    Job.GetRequest.SetHeader("Authorization", "key=" & Starter.API_KEY)
End Sub

Sub JobDone(job As HttpJob)
    Log(job)
    If job.Success Then
        Log(job.GetString)
    End If
    job.Release
End Sub

When the message arrives at the other end, you can place a marker on the map:
B4X:
'In FirebaseMessaging Service
Sub fm_MessageArrived (Message As RemoteMessage)
   
    CallSub2(Main, "updateMap", Message)
    
End Sub

'In Main Activity
Public Sub updateMap(msg As RemoteMessage)
    Private lat As Double = msg.GetData.Get("lat")
    Private lon As Double = msg.GetData.Get("lon")
    Private m1 As Marker = gmap.AddMarker2(lat, lon, msg.GetData.Get("sendername"), gmap.HUE_RED)
    'If you then want the map to pan & zoom to the latest marker added
    pos.Initialize(lat, lon, markerZoom)
    gmap.AnimateCamera(pos)
End Sub

That's basically it in terms of the mechanics of sending & receiving positions, then plotting them on a map. In the FCM message you can put whatever labels & messages you want, by adding them to your "data" map - so if you want to give your users the option of sending a position manually with a message, you can just add a "message": msg pair to the map.

- Colin.
 
Upvote 0

maleche

Active Member
Licensed User
Longtime User
WooHoo!
Thank you Colin!
i look forward to trying this out!
you're the best!
Respectfully,
Doyle
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
No. FCM <> incoming connection. The OS connects to Google servers and receives the push message.
Thanks - all good. Just wanted clarification for those who might be thinking of using FCM.

- Colin.
 
Upvote 0
Top