Cell phone clients
There are 2 parts to the gps tracker application. The server and the clients. The server part needs to be installed on a public web server. It can be installed on a local machine and clients can be tested over wifi so strictly speaking, you do not need a public facing web server but for our purposes, we will assume you have one. There are 2 different server stacks:
- one for asp.net and sql server
- one for php and mysql
You do not need to install both. How do you choose which one to use? It’s personal preference, but if you work primarily on windows machines, it makes sense to install the asp.net version.
Asp.Net and Sql Server
The asp.net version requires you to install IIS (Internet Information Services 7 or greater) onto your machine and when you do install it, do not forget to install asp.net, you have to click a separate checkbox. Forgetting to install asp.net will result in a very interesting and hard to solve error… In IIS manager, right click on “Default Web Site” and create a new application named gpstracker and put all the files from the dotNet server directory that you downloaded and put it into that application. The application will probably be mapped to the physical directory C:\inetpub\wwwroot\gpstracker. Add files there.
You need to also install sql server. I used sql server express 2012 which is a free download. Once sql server in installed you need to do a restore. The file is in the servers > dotNet > sqlserver directory and is called gpstracker.bak. In the sql server management console, expand the System Databases and right click on one of the databases and go to Tasks > Restore > Database and restore GpsTracker bak file. Once that is done, your database is ready to go. Make sure to set a user name and password on that DB. I beleive that username “gpstracker” and password “gpstracker” are in that DB currently. Don’t forget to change that if you use the DB in production…
Download Visual Studio Express 2012 for Web and on the File menu, click “Open Web Site” and then choose local IIS on the left and then gpstracker on the right. I had to open visual studio as administrator for it to work right with IIS permissions. Now you can see all the website files. DisplayMap.aspx is the one that you want to view. Use visual studio to establish the connection with sql server (under Tools > Connect To Database). You can set DisplayMap.aspx as the start page and then run the application on the menu. That should get you going on the asp.net server.
PHP and MySql
For this, you need a LAMP stack or one of its derivatives (MAMP, WAMP etc). LAMP stands for linux, apache, mysql and php. You can download packages that will install all at once, just google lamp, mamp and wamp. They are all similar but just different based on the platform you have, windows, mac or linux. Once you have your server software installed, you need to create a website on your apache webserver and create a directory called gpstracker. Put all of the files from the php download directory into there.
From the command line, you need to do the following (windows users may need to install cygwin, which will give them a unix-like terminal prompt). Login in to MySql with this command:
mysql -h localhost -u root -proot_password
Change root_password to your root password and note that there is no space between the -p and your password.
and now from the mysql prompt, create the gps tracker database with this command:
CREATE DATABASE gpstracker;
and don’t forget the semi-colon ; at the end, all MySql commands must end in semi-colons. Now exit MySql with the following command:
Now lets get our data and stored procedures into the database using the following command:
mysql -h localhost -u root -p root_password gpstracker < gpstracker-03-14-14.sql;
Please note that the date on the sql file (03-14-14) may be more current. Use the most current from the github repo.
Now log back into MySql with the above command and switch to the gpstracker DB with this command:
and then have a look at your location records with this:
select * from gpslocations order by gpsLocationID desc limit 10;
Finally, create a user called gpstracker_user for the web application:
GRANT ALL PRIVILEGES ON gpstracker.* TO 'gpstracker_user'@'localhost' IDENTIFIED BY 'gpstracker’;
the final ‘gpstracker’ in parentheses is the password for gpstracker_user. You need to change that to your own password and then you need to change it also in dbconnect.php here:
$dbpass = 'gpstracker';
While you are in dbconnect.php, make sure that the database name is the same as the one you just created. If you are using phpMySql, the database name will probably be different.
and finally exit out of mysql with this:
Ok, at this point displaymap.php should work in your browser and you should be able to see the one location stored in the database.
At this point in time, you should have one of the two servers above installed. Now its time to look at the clients. There are currently 4 clients. One for android, ios, windows phone and java me/j2me. You only need one client but all four clients work with either server, this is a very flexible system. We’ll start with android since that is the one that people seem to be testing the most.
Android Cell Phones
You can get the android client in one of two ways now. If you do not need to customize the app, you can download it directly from google play and easily change the upload directory to point to your Gps Tracker website. It’s available here:
If you need to modify and compile the android client, that requires Android Studio.
I urge android developers to start using Android Studio (AS) if you haven’t started already. Google has done an excellent job with AS, the gradle build system is excellent. After you install AS, open up the application by selecting import project (in the first popup window of Android Studio or on the File menu) and then selecting the build.gradle file in the GpsTracker > phoneClients > android directory. From the menu, select Tools > Android > SDK Manager. Select everything under Tools, Android 4.4.2 and Extras (down at the bottom). Then install those packages. In the next screen, click on the top Package on the left side, then on the right select “Accept License”, then click Install. This could take some time depending on your internet speed. Once this has completed, reopen the SDK Manager and make sure that the installs actually happened. It’s easy to mess this up if it’s your first time, so best to check. This hopefully should take care of gradle build issues that some people have been having. Finally, attach your android phone and make sure that its set up for development as explained here:
From the Android Studio Run menu, select Run to start the application on the phone. Enter a user name and then tap the tracking button. When you start tracking, the phone will send a gps location to the websmithing test website.
defaultUploadWebsite = "https://www.websmithing.com/gpstracker/updatelocation.php";
You can go to this webpage after you have run the app on the phone and find your location.
It’s a good idea to use the test page first because that let’s you know later on when you try to use your own server whether its the phone that is not working or the server that is not working. Once you have confirmed that the phone works with websmithing’s displaymap page, the it’s time to change the upload website to one of the servers you created above. Just change the server url text field when you start the application and then save it.
Ok, this should get you going on android, let’s turn our attention to iOS.
Getting your iOS device working requires xcode. Xcode can be found in the app store here:
This project uses AFNetworking, a popular http library. I decided to use it because it has a method to easily convert a dictionary of strings into the required format needed for sending a post request and also it automatically handles making http calls in a background task. Well worth the effort of installing it. So, to install it, you need to install cocoapods, which is a dependency manager (java users think maven…) more or less. Here are instructions on installing cocoapods:
Once you have that installed, go to the phoneClients > ios directory (where the Podfile is located) and from the command prompt run the following command:
To open the project, you need to click on the GpsTracker.xcworkspace icon, not the normal GpsTracker.xcodeproj. This is to make sure AFNetworking loads properly. When you start xcode, it may ask you if you want to enter developer mode, select yes.
Plug in your phone and in the upper left hand corner, make sure it is selected from the drop down box. As with the Android device above, you can test the application with the websmithing displaymap test page. When you have confirmed that the app is working with websmithing, change defaultUploadWebsite on line 181 of WSViewController.m to point to your web server that you have set up above.
The windows phone app can be opened with Visual Studio Express 2012 for Windows Phone.
With windows phone, you need to register your phone for development. Microsoft explains how to do it here:
Make sure your phone is unlocked and then install the app on the phone. After you have tested the phone with the websmithing displaymap page, you can point the phone to your own webserver by changing defaultUploadWebsite on line 77 of MainPage.xaml.cs. Don’t forget to change line 87, phonenumber, to something other than windowsPhoneUser. It will help you in testing.
Java Me / J2Me Phones
This is what Gps Tracker was originally written for. Before iPhone and android came out, most phones were j2me phones. The reason why I continue to support these old phones is because there is a possibility that there are still more of these (mostly inexpensive) phones still being used than there are android phones! Android may not be the mostly widely used mobile platform! Android may not be the mostly widely used mobile platform according to Fortune magazine. So I continue to support it.
To work with the java me application, I used Netbeans version 7.4 on Windows. I ended up installing it in my windows 8 virtualbox. I tried running it on my macbook pro but had some real problems with it. It was easier to run it in virtualbox. Anyway, here is the netbeans download:
I only tested the app out in the browser because I did not have one of those older phones easily available. But in essence, you created a .jad file and install that on the java me phone. You can even email the file to your phone and open that up on the phone.
Now that I have finished this quick guide, I will be writing more in depth tutorials for each of the servers and clients. They will be coming soon!