How to text your Location to a Phone and Display the Location on a Google Map

Use the Texting and LocationSensor components to send your location to a phone by sms.

The code shown below in the send Location Procedure prevents the message from transmitting until after your GPS receives a satellite fix. The Android must first decide where it is located prior to sending its location. The satellite fix must be obtained so the GPS knows where it is. The satellite fix normally occurs from 30 to 60 seconds after loading the app. Press the send Button and wait until you see a message indicating the message has been sent. The LocationSensor attempts a satellite fix every 30 seconds. It may take a minute the message is sent while the GPS is deciding it knows where it is located.

The tutorial code generates a message displaying your present geocoordinates and your current address (provided the information is available).

locationTextMsg

Otherwise a message No location available will display. The message is sent as a Text to the phone number you provide. The example shows how to use a single phone number. textingPhone
Place the number you want to text to in the Text Block circled. Various methods to allow the user to select a number from a List or a database are possible. You code the selecting flexibility.

To send the sms message directly containing your Location information (geocoordinates and CurrentAddress) without user intervention, use the SendMessageDirect Block to develop your app. Compile the app using a Companion with a 'u' designation.

You do not need to use the 'u' Companion to build your app. Use the SendMessage Block to send the sms location message using manual control and the device's Messaging app.

Your app probably will be rejected by GooglePlay when you code using the 'u' designation and SendMessageDirect. GooglePlay might provide you a waiver to publish (but probably will not). You will not have this issue if you build with the SendMessage Block. Why? See the Texting component documentation http://ai2.appinventor.mit.edu/reference/components/social.html#Texting .

The Location in the device Settings must be enabled to use the LocationSensor.

LocationSettings
The display to turn on Location shown in Settings varies depending on the phone's operating system version. This display shows an Android 4 screen.

Once the text message is sent, the phone you send the message to will receive a text using its Messaging app. The message will look something like shown below. On some phones and with some phone providers, touching the Address part of the message will invoke Google Maps and permit the phone to display the location you sent on a map.

This feature to use the Text to link to a Google Map works on an Android 4.2.2 cell phone connected to the Internet using WIFI or network. Touching the address information underlined in the Text message to provide a map might not work on Android's 5+ and might not work with some cell phone providers.

The Blocks

**

**

The 'u' Companion Version
about about2

The non 'u' version usually installs automatically from GooglePlay; to install a 'u' version on your phone, Help>Update the Companion and scan the bar code.

SendLocationWithSMS.aia (3.4 KB)

Best regards,
Steve

3 Likes