Line string from current location to selected location

673 views
Skip to first unread message

Rohit Radhakrishnan

unread,
Nov 7, 2019, 12:14:02 AM11/7/19
to MIT App Inventor Forum
Hello,

I am making an app for emergency vehicle where as soon as screen pops up, a line string for navigation becomes visible from our current location (changing with time) to one of the marked hospitals.

 I have no clue as to how to use the line string and update it with the current location. Kindly do the needy. Please help.

Chris Ward

unread,
Nov 7, 2019, 6:32:04 AM11/7/19
to MIT App Inventor Forum
Hello Rohit

There could be a fundamental requirement for your App to work - Android Background Services. Unfortunately, App Inventor does not support Background services.

It sounds like you have not coded anything yet. If you can give a concise, thorough and full description of what the App must do (time duration being an important consideration), then we can tell you if App Inventor is the right choice to code it. 

SteveJG

unread,
Nov 7, 2019, 9:00:41 AM11/7/19
to MIT App Inventor Forum
The Line component can be used to show the straight-line distance.  If you need to show a route, use this tutorial that shows how to do display a route with the Map component and OpenStreetMap tiles  HOW TO use the new Map Control. plot a route and post driving distance and time .   

This tutorial How to display Map runtime Markers, calculate distances, determine closest  shows how to do something similar (calculate distance and display a route)

and this mini-tutorial explains HOW TO: Use a Google Spreadsheet hosted on your Google Drive to update a Map  (the example uses pharmacies (but not hospitals).  Some of this 
stuff might be useful in planning your map.



If you really want to use the LineString,  you might use it like this   

zLineStringExample.PNG

The example code shows how to get from the MIT campus to Fenway Park.  It displays the distance you would travel if you had a helicopter and went straight to the park.  Substitute your current location coordinates where shown with the Fuchsia  arrows and the example will draw a line from your present location to the park instead of from MIT.

Why does this work?  Read the LineString documentation here> Map components for more information.


Did this help?

Regards,
Steve


Rohit Radhakrishnan

unread,
Nov 8, 2019, 12:40:36 AM11/8/19
to MIT App Inventor Forum
Hello,

Thank you for your response.

My app is made specifically for emergency vehicles (ambulances in this case). It has three functions:

1. To get priority green traffic signal (which is done by sending out GPS coordinates continuously).
2. Send out a request signal to a hospital and know whether it is ok to bring in the patient. If yes, the route to the hospital from the current location (the location where the patient was picked up). If not, the app has to automatically select one of the local nearby hospitals (with top facilities) and show the (quickest) route to the hospital.
3. The patient details from the equipments in the ambulance are collected and shown on app. The details are simultaneously sent to the server of the hospital and shown in hospital. This is done to give priority based on whether patient is critical or not.

I have pretty much completed 1


Rohit Radhakrishnan

unread,
Nov 8, 2019, 5:47:36 AM11/8/19
to MIT App Inventor Forum
NEW update of the project as per the supervisor!

(Modifying last message to the new updated objectives. I am not exploiting your help. I am not able to smoothly execute some of the functions. Please, please do help the needy.)

Hello,

Thank you for your response.

My app is made specifically for emergency vehicles (ambulances in this case). It has three functions:

1. To get priority green traffic signal (which is done by sending out NMEA GPS data continuously as a 40-byte packet via 32-bit PIC and RF Transmitter).
2. Send out a request signal to a hospital and know whether it is ok to bring in the patient. If yes, the route to the hospital from the current location (the location where the patient was picked up). If not, the app has to automatically select one of the local nearby hospitals (with top facilities) and show the (quickest) route to the hospital. Bearing action should show how we must move/take turn on the map to reach the destination.
3. The patient details from the equipments in the ambulance are collected and shown on app. The details are simultaneously sent to the server of the hospital and shown in hospital. This is done to give priority based on whether the patient is critical or not.

Number 1... How to get the NMEA GPS data and embed it to our app? How to take bearing and display it on map?
Number 2... I have been asked not to use Google Maps and instead take advantage of OpenStreetMap, as it is free. How to unlock/find API for OSM and embed it to our app?

SteveJG

unread,
Nov 8, 2019, 8:20:52 AM11/8/19
to MIT App Inventor Forum
You have to build this app yourself Rohit and to do that you have to learn how to program code with the App Inventor 2 Blocks.

To help you start learning how to use App Inventor, Here are some resources to help you learn to use the AI2 tools  A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .



What you want to do is very complicated. Are you an accomplished App Inventor 2 programmer?   There is no tutorial showing how to build this complex app.   A suggestion is to build a part of it at a time,. making several Projects.  When you get each of the Projects to work as you want, then combine them.


Regarding Number 1... How to get the NMEA GPS data and embed it to our app?    That can currently only be done using the AdvancedLocationSensor extension.  The extension can handle NEMA sentences.  See https://groups.google.com/forum/#!msg/mitappinventortest/kxmfu9QPIJc/kr3QNZ93CgAJ for advice on how to use ALS.

How to take bearing and display it on map?  There are Blocks in the MIT Map component that help you do that.  Search the Forum...there is a discussion where someone does that with a sail boat project.

Regarding Number 2... I have been asked not to use Google Maps and instead take advantage of OpenStreetMap, as it is free. How to unlock/find API for OSM and embed it to our app?  You use the MIT Map component.  The component uses OSM.     see  Map components for the documentation.

Regarding  Send out a request signal to a hospital and know whether it is ok to bring in the patient. If yes, the route to the hospital from the current location (the location where the patient was picked up). If not, the app has to automatically select one of the local nearby hospitals (with top facilities) and show the (quickest) route to the hospital. I already answered that question..  There are several links in my post of November 7th that explain how to do most of that.  You will have to adapt the tutorials to do exactly what you want to do  Did you read the Forum discussions?  Did you download the aia files and experiment?   It appears you did not.

You have a lot of reading and experimenting to do to construct your app Rohit.  Good luck.

Regards,
Steve

Rohit Radhakrishnan

unread,
Nov 11, 2019, 1:08:36 AM11/11/19
to MIT App Inventor Forum

Rohit Radhakrishnan rohitradha...@gmail.com

Sat, Nov 9, 11:51 AM (2 days ago)
to mitappinventortest
Thank You for the response, sir.

Yes, I understand the project is complex. I am studying and ring to figure out a way to merge them together. This, according to my supervisor, would be a big positive step for healthcare.

Yes sir, I am trying my best to learn about app inventor and make the app by myself.

Sir, I downloaded the aia files and experiment and I understood how to apply them.

Also, thank you for referencing the sail boat app. It would be easier to implement that function. :)

Thank you sir. 

Sir one more thing...

I was told that I have to send NMEA data but in RMC format of NMEA sentence. The data obtained while using advancelocationsensor is not RMC format (I may be wrong). 

ScreenshotApp.jpg


Is there any other Sensor Component which can be used to extract RMC NMEA data?

SteveJG

unread,
Nov 11, 2019, 10:30:38 AM11/11/19
to mitappinv...@googlegroups.com
Developers know how a GPS receiver works and how and what the satellites transmit. You do not presently understand that and do not understand how Niclas' tool works.
From the image you sent, you  probably do not need the ALS, the regular LocationSensor will provide what is required in your app.

You are making buildinf your app much more difficult than it should be Rohit.

Why does the app need to use $GPRMC NEMA strings exclusively? The ALS (and the regular LocationSensor) both use $GPRMC sentences.  The ALS exposes the strings; the LocationSensor hides them from the developer. The ALS uses whatever NEMA strings are required to provide location information. The ALS predominately uses $GPRMC strings.


"The data obtained while using advancelocationsensor is not RMC format (I may be wrong)".  Yes, you are wrong.  The ALS collects all NEMA data, among strings collected they are primarily $GPRMC strings Rohit. 

You don't believe?  Add a Label to Niclas Gins' tutorial Screen.  I added Label 5.  Within the NemaReceived block add this if statement

zALSNEMA.PNG

and Niclas' example will display all the RMC sentences captured by the GPS receiver as shown below:

NEMA.jpg



Niclas's ALS parses the strings for you.  When the example reports a location, his example does not show the actual nema sentences.  It provides the location information that is contained in as many nema strings that the gps receiver hears that are valid and combined to calculate the best information possible for reception conditions.   At a minimum, it uses three sentences; under ideal conditions and depending on how many channels the gps receiver in your Android has, it might  use a dozen or more satellite fixes.

Do you want to parse the nema sentences yourself?

A RMC string looks like this example:


$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A


Field Meaning
0 Message ID $GPRMC
1 UTC of position fix
2 Status A=active or V=void
3 Latitude
4 Longitude
5 Speed over the ground in knots
6 Track angle in degrees (True)
7 Date
8 Magnetic variation in degrees
9 The checksum data, always begins with *


As the extension indicates, it is an ADVANCED Location Sensor tool that provides significantly more information than is required for most apps and certainly your app.



Regards,
Steve









Rohit Radhakrishnan

unread,
Nov 21, 2019, 4:16:08 AM11/21/19
to MIT App Inventor Forum
Thank you for the response, Steve.

An additional part is to make a list of nearby hospitals. The route to the closest hospital has to be selected IF the first fixed hospital fails to positively respond to a request message from the ambulance (which has our mobile app).

The list of nearby hospitals are not available in advance as a list. With changing location, the route to the nearest hospital in THAT locality has to appear in our map.

Kindly help in finding the route to the nearest hospital.

SteveJG

unread,
Nov 21, 2019, 8:43:17 AM11/21/19
to MIT App Inventor Forum
See the Nov 7 post Rohit.  This tutorial shows how to take a list of locations (in your case hospitals), sort them from nearest to farthest from the Android, then a way to plot a route.  You did not do the tutorial  HOW TO use the new Map Control. plot a route and post driving distance and time .   ?      You say the list of hospitals is not available as a List, how are they available?  

You also said "With changing location, the route to the nearest hospital in THAT locality has to appear in our map." ...the tutorials do not explain how to do that; a simple way would be to re-run the app and let it sort out the nearest hospital again.   All depends on where the app is getting the hospital location information from.  Here is a similar app that loads information from a Google spreadsheet for pharmacies .  The spreadsheet needs to be updated by computer as necessary .  Here is the link https://groups.google.com/forum/#!msg/mitappinventortest/YeZQwF3YvNg/xGcyo5I8AwAJ         .  You will have to adapt the example to your requirements or include the ability to provide you app with a link to an outside database; whether that is a spreadsheet or a CloudDB etc.

"Kindly help in finding the route to the nearest hospital." ... there are two ways to do that, one is use the hospital coordinates in an ActivityStarter call to Google Navigate the other way is to use the advice for the How To use the new Map Control. plot a route..... tutorial and use the less limited capabilities of OpenStreetMap.

Regards,
Steve                

Rohit Radhakrishnan

unread,
Nov 27, 2019, 1:24:14 AM11/27/19
to MIT App Inventor Forum
Thank you for the response, Steve.

As per your instructions, I was able to route the position from current location to a recorded location (a hospital).

What I need to do is to show the route to the nearest hospital if the selected hospital doesn't respond to a request positively.
From the tutorials and other works, I learned that we can apply the Distance between points to get the shortest distance.

But how can we make our app select the closest local hospital and show route using spreadsheet/cloudDB? Is it possible and accurate?

Re-running app might be a disadvantage especially in crunch situations of ambulance.

Rohit Radhakrishnan

unread,
Nov 27, 2019, 4:46:49 AM11/27/19
to MIT App Inventor Forum
Another thing, sir.

Earlier, I was able to send the latitude/longitude values of every passing second  from my mobile app to the bluetooth of SIM868. The problem arises when I am not able to retrieve, let alone send, data in the following format:

eg: "E308309199076556513051217170252187x", 
 where E -> name of product
            3->No. of vehicle with the product
            followed by Latitude (08309199), Longitude, date (in dd.MM.YY format), Time (in hh.MM.ss format), Bearing point and checksum w.r.t $GPRMC.

Kindly help, sir.

            

Rohit Radhakrishnan

unread,
Nov 27, 2019, 4:51:33 AM11/27/19
to MIT App Inventor Forum
Sir

Here is the Blocks image of the app so far which can display current $GPRMC value, Satellite Time and show route from our current position to a selected, pre-determined location (Hospital).

blocks (1).png

SteveJG

unread,
Nov 27, 2019, 5:17:26 PM11/27/19
to mitappinv...@googlegroups.com
It's certainly time you make use of the resources you are pointed to Roghit. Here is some help.

What I need to do is to show the route to the nearest hospital if the selected hospital doesn't respond to a request positively.
From the tutorials and other works, I learned that we can apply the Distance between points to get the shortest distance.

You easily get the straight-line distance between Android and the points, not the driving distance from your existing app. The app calculates the distance from the Android to each of the locations in your database .   You were previously directed to where to get help about how to produce a route on 7 November    If you need to show a route, use this tutorial/ it shows how to do display a route with the Map component and OpenStreetMap tiles  HOW TO use the new Map Control. plot a route and post driving distance and time  Another way to display the route is shown in the tutorial How to display Map runtime Markers, calculate distances, determine closest  .  It shows how to do something similar (calculate distance and display a route)   Take your pick.   

Use the ActivityStarter  to use Google Navigate or use the Map component, (OSM uses a similar algorithm provided which is not as robust as Google's information).  Use what makes you happy.    

Regarding "to show the route to the nearest hospital if the selected hospital doesn't respond to a request positively"  be aware, the examples only select the SHORTEST distance from a List the app creates even though it calculates all of them.  To show the next nearest means you have to use that List of distances to all the hospitals and provide location with the next shortest distance.  Code that part of your using the skills you have acquired. What you do depends on how you created your app's Blocks.


But how can we make our app select the closest local hospital and show route using spreadsheet/cloudDB? 
Is it possible and accurate? Should be. Why don't you check the distances on a paper map.   You can do something similar to provide the locatiton information using the MIT CloudDB component.  If you make a commercial app using the CloudDb, you need to use your own Redis server.

Re-running app might be a disadvantage especially in crunch situations of ambulance.  Oh, really, it takes only a few seconds to close the app and rerun it.  Alternatively, you can provide a 'Recalculate Nearest Distance' button in your app.

Regarding using your Bluetooth, I don't know.   I don't code that stuff.

Good luck with your Project.

About your blocks using the AdvancedLocationSensor... these Blocks might work. Did you try them and are you happy?   As I said previously, you do not need the ALS.  I suspect you could code a much simpler app using just the LocationSensor.


Regards,
Steve

Rohit Radhakrishnan

unread,
Nov 27, 2019, 11:12:09 PM11/27/19
to MIT App Inventor Forum
Sir,
 
You easily get the straight-line distance between Android and the points, not the driving distance from your existing app. The app calculates the distance from the Android to each of the locations in your database .   You were previously directed to where to get help about how to produce a route on 7 November    If you need to show a route, use this tutorial/ it shows how to do display a route with the Map component and OpenStreetMap tiles  HOW TO use the new Map Control. plot a route and post driving distance and time  Another way to display the route is shown in the tutorial How to display Map runtime Markers, calculate distances, determine closest  .  It shows how to do something similar (calculate distance and display a route)   Take your pick.   

I did as you had directed back then. The route was obtained. There is no confusion at all regarding getting the route and showing time required and distance in description for one particular location. I had a little trouble in adapting the spreadsheet to find location of new, nearest hospital. I tried to understand your example (Algerian Pharmacy) and tried to apply it but it did not work. I will work on it and find the peril obstructing the use of spreadsheet. 
 
Use the ActivityStarter  to use Google Navigate or use the Map component, (OSM uses a similar algorithm provided which is not as robust as Google's information).  Use what makes you happy.    

Regarding "to show the route to the nearest hospital if the selected hospital doesn't respond to a request positively"  be aware, the examples only select the SHORTEST distance from a List the app creates even though it calculates all of them.  To show the next nearest means you have to use that List of distances to all the hospitals and provide location with the next shortest distance.  Code that part of your using the skills you have acquired. What you do depends on how you created your app's Blocks.

Got it, sir. 

But how can we make our app select the closest local hospital and show route using spreadsheet/cloudDB? 
Is it possible and accurate? Should be. Why don't you check the distances on a paper map.   You can do something similar to provide the locatiton information using the MIT CloudDB component.  If you make a commercial app using the CloudDb, you need to use your own Redis server.
 
I was oblivious to the need of Redis server. Thank you for pointing that out, sir. The app is not purely commercial but will be available for different hospitals (and ambulances).

 

Re-running app might be a disadvantage especially in crunch situations of ambulance.  Oh, really, it takes only a few seconds to close the app and rerun it.  Alternatively, you can provide a 'Recalculate Nearest Distance' button in your app.
 
 Excellent idea, sir! That will make it easier to get the desired result.

Good luck with your Project.
 
 Sir, I am just a student who's new to app development. I am trying my best to understand and develop the app. With your help and guidance, I hope to make this app and do so in a smooth way. Thank you sir for helping me and others.

About your blocks using the AdvancedLocationSensor... these Blocks might work. Did you try them and are you happy?   As I said previously, you do not need the ALS.  I suspect you could code a much simpler app using just the LocationSensor.

I'll try that, sir.

About the bluetooth coding stuff, while I was able to transmit data of small length (either latitude or longitude values), the different values (latitude, longitude, etc) were not able to be extracted and send via bluetooth block. The app just remains silent. In fact, even the $GPRMC sentence (as an example to test the app) was not send from app. How can we extract the values from the $GPRMC sentence? 

Kindly help, sir.



Regards,
Rohit
 

SteveJG

unread,
Nov 28, 2019, 9:09:25 AM11/28/19
to MIT App Inventor Forum
How to parse a string  by Taifun ...     How to parse a result  shows one way.

You would do something like that with your string

E308309199076556513051217170252187x ... you want the results to separate like:
E
3
08309199
07655651
3051217170252187x   < where this mess is date (in dd.MM.YY format), Time (in hh.MM.ss format), Bearing point and checksum w.r.t $GPRMC  but only you know what is what.

If the positions of 'thing' you want to extract are always the same (the data is always in exactly the same numerical position in the string; you could do this:

xxxsimpleParse.PNG


There are fancier ways to do these separations.  The above example shows a very simple way to parse that string that works.


Does the Android screen separate the parts of the screen correctly?   If so, then you only need to extract the other stuff?


When you  ask additional questions, please start a new Forum discussion.  Your original question was answered on 7 Nov. I locked this topic.




Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages