Delphi XE5 iOS and Android One Line of Code App - Map My Location
To start this Delphi XE5 mobile project, choose the "File | New | FireMonkey Mobile Application - Delphi" IDE menu choice.. This brings up the Mobile Project template library.

I chose the "Blank Application" template. On the blank form I added a TToolBar component and set its alignment to Top. I added a TLabel component to the TToolBar and set the label's Text property to "Map My Location". I set the Label's TextAlign property to center and its Alignment proprty to alHorizCenter so that the label is in the center of the ToolBar. I added a TWebBrowser component onto the form and set its Alignment property to alClient so that it takes over the rest of the form's client area. I finally added a TLocationSensor component to the form so that I can get the latitude and longitude from the GPS sensor on my Apple iPhone and Samsung Galaxy S4. I set the TLocationSensor's Active property to True so that it gets the location whenever I run the app.
Here is what the Delphi XE5 IDE looks after all of the components and property settings are made. You can click on each of the bitmaps to see larger versions of the form, object inspector and project manager.




For my one line of code app, I set the TLocationSensor's OnLocationChanged event handler by selecting the TLocationSensor, switched the Object Inspector to the Events tab and double clicked on the OnLocationChanged event to create the following event handler and added my "one line of code":
procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
begin
WebBrowser1.Navigate(
Format(
'https://maps.google.com/maps?q=%s,%s&output=embed',
[NewLocation.Latitude.ToString, NewLocation.Longitude.ToString]
)
);
end;
The line of code takes the NewLocation Latitude and Longitude that comes from the GPS, converts the double precision floating point values (TLocationCoord2D) to strings using the ToString helper function, inserts the two values into the string using the Format function and passes the resulting string to the TWebBrowser's Navigate method.

Then I compiled and deployed the app to my Android and iOS devices by activating each of the target platform choices. The resulting screen grabs on my Apple iPhone 4S and Samsung Galaxy S4 show the one line code app running on each device.


What iOS and Android Delphi XE5 app can you create using one line of code? Join the fun of creating multi-device apps using Delphi and the FM Application Platform. If you don't have Delphi XE5, you can download the Instant Trial or Standard Trial at http://www.embarcadero.com/products/delphi/downloads.


Comments
-
Joseph: the one line of actual written (by me) code:
WebBrowser1.Navigate(
Format(
'https://maps.google.com/maps?q=%s,%s&output=embed',
[NewLocation.Latitude.ToString, NewLocation.Longitude.ToString]
)
); -
Jenny Sunday, 3 November 2013
Really?
How useful is this kind of application and as developer how much money do you think I'm going to make selling this? Probably ZERO.
Bring something useful, build useful demos like Apple and Google demos.
This kind of demo doesn't help to convince my self to use Delphi for mobile development. -
Jenny - thanks for the suggestion. This specific blog post was to show how to do something simple. We build many other much more involved demos for webinars, tours, articles and other blog posts.
DO you have specific "useful demos like Apple and Google demos" in mind? Maybe you can post some URLs to demo scripts, videos and examples you like from Apple and Google and I can build the same ones using Delphi for iOS and Android - that would be fun. -
Joseph G. Mitzen Sunday, 3 November 2013
Mr. Intersimone,
>Joseph: the one line of actual written (by me) code:
Fair enough, although the system does generate a reasonable amount of code.
Would other development tools (such as the official ones) require writing any more code to produce the same thing? That would be an even more interesting example for me. Honestly, it's the Google Maps website that's really doing most of the work here, so I'd be surprised if it was much more difficult to write in another language (but I could be wrong).
>Joseph and others - I could write a blog post showing how you can build a multi-device,
>multi-tier, master detail database application with no lines of code using database components,
>datasnap
And I could write a real one-line program in Python ;-)
sorted(set(open('somewords.txt')))
That would open a file (a list of words), build a set of unique words, then return a list with the words sorted. There's nothing wrong with playing Code Golf with Delphi, but it would be good if we saw something really unique or powerful rather than just displaying a web page with the IDE generating the rest of the boilerplate code needed. Java is a verbose language; I'd love to see how long the Java equivalent is. -
Rolf Warnecke Sunday, 3 November 2013
@davidi:
A useful demo for me is it to show how can I perform a lot of datasets into a listbox. I write on a ios app who had 10 or more datasets. If I show it in a listbox the application hangs for a few second. Under the vcl the program doesn't hang if I like to show 10 or more datasets in a listbox. -
Dennis Sunday, 3 November 2013
You should challenge Mr. Swindell to not use marketing stuff that won't work for developers ("One line of code only"). That's nothing they're interested in. They are interested in functional demos showing all the good things hidden in fmx - no matter how many lines of code they would consist of. Stop marketing for idiots, start marketing for developers.
-
John Sunday, 3 November 2013
David, you asked for some demo video. I saw an interesing video showcasing an app that was made with Delphi XE5
http://www.youtube.com/watch?v=kZkGBwHN1EQ
This is the kind of things you should be adverting, showing how powerfull Delphi XE5 can be and what kind of applications could be made out of it... Also, this video shows how good the performance can be with Firemonkey, since they managed to make a very smooth application with Firemonkey (Something that people always bitch about, performance) -
Leonardo Herrera Sunday, 3 November 2013
@Jenny - are you really asking for a revenue-generating app written in one line of code? Really?
This is a nice little demo. I prefer this far more than creating a "hello world" app with Java: http://developer.android.com/training/basics/firstapp/index.html -
I'd like to make (and release) a port of the communication program here:
www.CtrlTerm.com
Just a socket version (no serial) would be very useful! Can anyone help me? -
Bunny - don't try to read too much into this one line of code blog post - what I am highlighting is how to use two of the many pre-built components, TLocationSensor and TWebBrowser, in a simple app that compiles and runs on iOS and Android. Of course, we can build much more complex applications using these and other components and RTL functions.
-
John - thanks for the YouTube link - we do have a load of videos showing much more you can do with Delphi and mobile including all of the CodeRage Mobile and CodeRage 8 sessions. I am working on additional videos and blog posts based on developer suggestions including BlueTooth, Serial, and NFC communications just to name three. Keep the suggestions coming and I'll write and record more for all of you.
-
Joseph - "There’s nothing wrong with playing Code Golf with Delphi, but it would be good if we saw something really unique or powerful rather than just displaying a web page with the IDE generating the rest of the boilerplate code needed. Java is a verbose language; I’d love to see how long the Java equivalent is."
I know that you can simply use your Google or Apple Maps app to get your location. In this post, I showed how to use two components to do the same thing. Hopefully this blog post will inspire some Delphi developers to build apps that take advantage of 2 of the hundreds of FM components to build the unique and powerful apps with Delphi XE5.
Maybe you or someone else would post a comment with the Java code for Android and iOS?
What example apps do you want me to write? -
Rolf - "A useful demo for me is it to show how can I perform a lot of datasets into a listbox. I write on a ios app who had 10 or more datasets. If I show it in a listbox the application hangs for a few second. Under the vcl the program doesn’t hang if I like to show 10 or more datasets in a listbox."
Use a ListView for displaying the results of dataset operations, not a ListBox - here are a few resource links for you and others:
http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_LiveBindings_to_Populate_a_ListView_(iOS_and_Android)
http://docwiki.embarcadero.com/Libraries/XE5/en/FMX.ListView.TListView
The FM R&D team is continuing work to provide higher performance for both ListView and ListBox components on iOS and Android. -
Andreas Wednesday, 11 December 2013
Hi David,
it's fine what we all can do with Delphi XE5, but mobile app with Android galaxy tab7 (OS 4.1.1) and Location Sensor doesn't work. No latitude or longitude will be shown.
I compiled the Delphi sensor demo.
is it a bug or are there some android Versions not supported? -
Please login first in order for you to submit comments
Either my math is really bad, or that's a lot more than one line of code!
>What iOS and Android Delphi XE5 app can you create using one line of code?
None, because Delphi has a lot of boilerplate code, no type inference, etc. Once I type
Program Whatever;
I've already used up my one line. :-( Same for declaring my first variable or writing a function header.