Author Archives: Nick Fox

Quick Start Guide for Gps Tracker

Servers

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:

exit;

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:

use gpstracker;

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:

exit;

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:

Gps Tracker in the Google Play Store

If you need to modify and compile the android client, that requires Android Studio.

http://developer.android.com/sdk/installing/studio.html

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:

http://developer.android.com/tools/device.html

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.

https://www.websmithing.com/gpstracker/displaymap.php

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.

iOS Devices

Getting your iOS device working requires xcode. Xcode can be found in the app store here:

https://itunes.apple.com/us/app/xcode/id497799835?mt=12

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:

http://guides.cocoapods.org/using/getting-started.html

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:

pod install

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.

Windows Phone

The windows phone app can be opened with Visual Studio Express 2012 for Windows Phone.

http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff630878(v=vs.105).aspx

With windows phone, you need to register your phone for development. Microsoft explains how to do it here:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769508(v=vs.105).aspx

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:

https://netbeans.org/downloads/

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!

Version 3 of Gps Tracker has been released!

gps trackerI’m happy to report that version 3 of GpsTracker has shipped. This is a major change and the application now supports tracking of android, ios, windows phone and java me/j2me cell phones using google maps. What the application does is track cell phones periodically using gps, wifi and/or cell towers. It allows you to track a phone every minute or every 5 minutes or whatever you want and display it on a google map. You can view the tracking in real time or view previously saved routes.

The software is open source and MIT licensed. It took me a couple of months to write the new phone clients and this is now my full time job. Please donate with the button on the right if this software is useful to you and I hope you enjoy it.

I have put the software in 2 places, on github of course:

https://github.com/nickfox/GpsTracker

and on sourceforge:

https://sourceforge.net/projects/gpsmapper

I’m keeping the sourceforge account up to date because it still gets a lot of traffic, around 7,000 downloads a week. If you want the very latest then go to my github account, I am making commits daily.

Feel free to follow this blog by clicking on the orange button up to the right, tutorial and training videos on youtube will be coming soon.

Version 1 of Windows Phone Cell Phone Tracker is complete!

Making progress. The windows phone cell phone tracker is now complete and is fully operational with the test website on websmithing. You can find the source code here on github:

https://github.com/nickfox/GpsTracker/tree/master/phoneClients/windowsPhone

The original java ME / j2me phone app has also been updated to work with the websmithing website and can be found in the same repo. Both of these clients will work with the original gps tracker software. The android application is nearly complete and should be posted in a few days.

Android and iPhone gps tracker coming soon

I just wanted to let people know that I have been working on the google maps gps tracker for android and iphone. This will allow people to track their android or iphone and store routes. This can be very helpful for companies that need to track employees and see where an employee has been or currently is.

How to Sync Up an iphone App with Dropbox and a Couchdb Database in the Cloud

I was recently working on a project for a client and needed to sync up a catalog app on an iphone with data and images on the internet. The client wanted to be able to update the catalog on the internet and then have the iphone app automatically sync up. I’ve put the project on github and have directions there on how to install and the app.

The full source code for iPhoneCloudSync is here on github.

How to Update the UI in an Android Activity Using Data from a Background Service

Recently, I needed to update an activity in Android with data I gathered from a background Service. I couldn’t find any decent examples on the web or StackOverflow, so I decided to put one together. I really like when someone has a complete working sample, so I will provide that as well you can download the source code from Github at the end of this article. The Android project is very simple, with just two classes, the activity and the background service. We’ll take a look first at the background service to see how the data is generated.

The first thing that needs to be done is to create a string called BROADCAST_ACTION, this is simply a string that identifies what kind of action is taking place. Most of the time, it’s common to use the package name with the kind of action added to the end, so we’ll do that here. The next step is to create a handler that will be used to broadcast our data every 5 seconds. It’s better to use a Handler instead of Timer because a Timer creates a new thread.

public class BroadcastService  extends Service {
    private static final String TAG = "BroadcastService";
    public static final String BROADCAST_ACTION = "com.websmithing.broadcasttest.displayevent";
    private final Handler handler = new Handler();
    Intent intent;
    int counter = 0;

In onCreate, I’ve created a Intent and passed the BROADCAST_ACTION to the constructor of the intent. Notice that the Intent was defined as a global variable above. The intent will be called repeatedly in the Handler below and there is no reason to create a new intent every 5 seconds, so I’ll create it once here.

    @Override
    public void onCreate() {
        super.onCreate();
    	intent = new Intent(BROADCAST_ACTION);	
    }

In onStart, first we call removeCallbacks to remove any existing callbacks to the handler and make sure we don’t get more callbacks than we want. Then we call our handler with a one second delay. This will start our runnable object below.

    @Override
    public void onStart(Intent intent, int startId) {
        handler.removeCallbacks(sendUpdatesToUI);
        handler.postDelayed(sendUpdatesToUI, 1000); // 1 second   
    }

Our runnable object creates a new thread, performs whatever code is in the run method and then shuts down. In the run method, we do two things call the DisplayLoggingInfo method and then calls handler.postDelayed again but this time with a 5 second delay. This is how the repeating timer is created. One of the things that is nice about doing it this way, is that you can put a variable in place of 5000 and that way you can externally control the interval between call to the runnable object.

    private Runnable sendUpdatesToUI = new Runnable() {
    	public void run() {
    	    DisplayLoggingInfo();    		
    	    handler.postDelayed(this, 5000); // 5 seconds
    	}
    };  

In the following method, we add some data to our intent that was created above. I’m just adding the date and a simple counter that increments itself. Then we call sendBroadcast with that intent which sends a message and whoever is registered to receive that message will then get it.

    private void DisplayLoggingInfo() {
    	Log.d(TAG, "entered DisplayLoggingInfo");

    	intent.putExtra("time", new Date().toLocaleString());
    	intent.putExtra("counter", String.valueOf(++counter));
    	sendBroadcast(intent);
    }

At this point, the Service is completed and now it’s time to take a look at our Activity and see how we consume and display our data. The first thing we’ll do is create an intent with the name of the Service class. This will be passed to startService and stopService.

public class BroadcastTest extends Activity {
	private static final String TAG = "BroadcastTest";
	private Intent intent;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        intent = new Intent(this, BroadcastService.class);
    }

Now, we’ll create a BroadcastReceiver to receive the message that is going to be broadcast from the Service above. The BroadcastReceiver has one method, onReceive, it gets called and then the BroadcastReceiver object is destroyed. In the onReceive method, we call updateUI passing in our intent which is holding the data to display.

    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
        	updateUI(intent);       
        }
    };    

In onResume and onPause, we start and stop our Service. This happens when the screen (Activity) displays and goes away. We also register our BroadcastReceiver by passing in an IntentFilter. Do you see that the IntentFilter is using the same static string, BROADCAST_ACTION, that we created in the Service above. This is how we identify the message that is broadcast. in onPause, we also make sure that we call unregisterReceiver to stop listening for broadcasts.

	@Override
	public void onResume() {
		super.onResume();		
		startService(intent);
		registerReceiver(broadcastReceiver, new IntentFilter(BroadcastService.BROADCAST_ACTION));
	}
	
	@Override
	public void onPause() {
		super.onPause();
		unregisterReceiver(broadcastReceiver);
		stopService(intent); 		
	}

This last bit of code is pretty straight forward. We get our data out of the intent and set our two TextViews with the data. They will be updated every 5 seconds.

    private void updateUI(Intent intent) {
    	String counter = intent.getStringExtra("counter"); 
    	String time = intent.getStringExtra("time");
    	Log.d(TAG, counter);
    	Log.d(TAG, time);
    	
    	TextView txtDateTime = (TextView) findViewById(R.id.txtDateTime);  	
    	TextView txtCounter = (TextView) findViewById(R.id.txtCounter);
    	txtDateTime.setText(time);
    	txtCounter.setText(counter);
    }

I’ve made the entire project available for download here on GitHub.

Find your lost Android Cell Phone!

I’ve taken the open source GPS cell phone tracker and rewrote it so that it works with Android cell phones. Since I wrote the original tracker, I’ve had many people who are not developers ask me how they can track their cell phone. So I created a website that allows people to do that. You can download the app from the Android Market by searching for MyCellTracker and then going to:

www.mycelltracker.com

You can try the app free for 7 days and then subscribe for either $1.99/month or $19.95/year. Please give it a try and also click on the facebook like button if you would be so kind!