Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Delphi XE5 iOS and Android One Line of Code App - Map My Location

Discussion in 'Tutorials and Articles' started by AdminDF, Nov 21, 2013.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member DelphiFan Administrator Staff Member DF Staff

    Michael Swindell challenged us to create mobile apps using Delphi XE5 for iOS and Android with only one line of code. After thinking about this for awhile, here is my first one line of code app, "Map My Location".  This app uses the TLocationSensor, TToolBar, TLabel and TWebBrowser components to create an Android and iOS app that displays a Google map of my current 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.
    [​IMG]
    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.
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    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":[size=1em]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;[/size]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.
    [​IMG]
    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.
    IPHONE
    [​IMG]
    SAMSUNG S4
    [​IMG]
     
    prosoftgmxnetxx likes this.
  2. teste
    Offline

    teste DF Junior

    great job! thanks for sharing with us..  ;)
     
  3. perdcomp
    Offline

    perdcomp DF Junior

    thanks
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block