Category Archives: Google Map Gps Cell Phone Tracker

Link

This was a cover of “I Love LA” by Starcrawler I did. I lived in LA for 17 years and really do love LA.

I’m still alive and so is GpsTracker

I just wanted to let people know what’s going on with GpsTracker. It’s been a couple of years now since I’ve retired from software development. I spend most of time working on my guitar and I’m building a bathroom right now. I just updated the Android client to the latest software so I know that’s working properly. That is still the most popular client.

One thing I would like to mention is that Google is now requiring an API key to use Google Maps. So if things aren’t working, that’s a good place to look first.

https://developers.google.com/maps/documentation/javascript/get-api-key

I am still answering questions here on websmithing. Just create an account and ask on the appropriate page.

One last thing I’d like to say. I would like to update the GpsTracker iphone app. I no longer have an account with Apple and don’t want to spend the $100 that it requires. If you are an ios developer and would like to assist me in updating that, I would greatly appreciate it. If you would like to do the work for free, then I would include your name in the Change Log and you can use it as a reference for future employers. If you would prefer to be paid, I’m willing to pay $50 dollars but then I will just do the update without mentioning who the developer was. I think that sounds pretty fair.

Good luck in using GpsTracker and give me a yell if you need any help.

2 Million Downloads and Still Going Strong!

GpsTracker has now been downloaded over 2 million times on SourceForge. It’s also very popular on Github. I’ve been working on GpsTracker for about 10 years. I’m doing much less software work right now for several reasons. The first is I’ve been writing software for 20 years and I’m now 55 and writing software just isn’t as fun as it used to be and I’m no longer interested in dealing with all the stress.

So I decided it was time for a change. The first thing I did was to sell my house near Seattle, give away all my possessions (except for my stratocaster and tools) and move to France. I’m living in the mountains in a small chalet near Lac Leman where it is very quiet, very peaceful and very beautiful. Three things that I really need and want in my life right now. Also, I have decided to change careers. For the fifth time. So now I am writing my first book which is a work of fiction. I’ve been doing research for the past seven months in preparation for the book. This is definitely one of the riskier things I’ve done but life is too short to sit on the sidelines and in no way am I’m going to retire and watch the world go by. I don’t even know what “retirement” means to be honest. It’s just not in my DNA to sit around and look for amusing ways to fill my time until I die. People in my family tend to live a very long time, many close to 100. So as far as I’m concerned, I’ve just reached the halfway point in my life and I’m just getting warmed up.

Another reason why I’m winding down writing software and in particular, more software for GpsTracker is that it has not been as financially successful as I would have liked. I get approximately 200 to 300 dollars a month from Google Adsense which is nice. In the past 10 years, I’ve gotten about 400 dollars in donations. Nothing in GpsTracker is really that complicated (except for the WordPress plugin). When I first wrote GpsTracker, my goal was to write something that ran on several platforms as a learning tool for me. At first it was a simple PHP server running MySQL on the backend and a java ME client. This was before iPhone and Android came out. I, of course, added those clients as well as Windows Phone. And I wrote a complementary .NET server. Next I created a WordPress plugin which I consider to be the best piece of software I ever wrote.

The last piece of software I created for GpsTracker was a TK103 server and client. Have you ever seen those GPS trackers that you can just plug into the OBD (On Board Diagnostics) port in your car? Well, you can buy them on amazon and then you can pay some company about 20 to 50 dollars a month so that you can track your car. There are lots of companies that will do that for you. Well, I wanted to know how they did it so I ended up writing my own PHP socket server and client and integrating it with my WordPress plugin and there I was, tracking cars for free. I will admit that was a fun project. It was something I always wondered about.

I had a fellow developer, Brent Fraser, join me and he expanded the back end by creating SQLite and PostgreSQL databases for GpsTracker. The whole point of all this was to create a very flexible starting point for other developers so that they could take GpsTracker and work on the platforms that best suited their needs. I think we’ve done a very good job in achieving that goal.

I like helping people and I will continue to do so as time and desire permits. I’m going to create a forum here on websmithing to better organize questions and responses. At this point in time, I will not be taking on any new clients. I wish you luck and success with your software endeavors.

So anyway, that’s where I’m at and that’s where GpsTracker is at. Did I just end that sentence with a preposition? I really need to work on my writing skills…

 

Version 5 of Gps Tracker out now with support for WordPress!

The next version of Gps Tracker comes with a WordPress plugin and also an Android client. The plugin is available on the WordPress plugin website and you can install it directly from your WordPress install. The source code for the plugin is also now available in the Gps Tracker Github repo and Sourceforge download. The software is dual licensed. It uses MIT and GPLv2 licenses. The reason for the two licenses is because WordPress is GPLv2 licensed and recommends that their plugins be licensed that way also. The reason why I use MIT is because Gps Tracker has been licensed that way since the beginning and I wanted to maintain the same licensing for any new software added to Gps Tracker.

You can see the plugin working here on the websmithing website. This plugin took me about a year to write. I first had to learn how to create WordPress plugins and then how to fit Gps Tracker around their API and it was not easy. I’m using WordPress in a non-standard way. I have created a REST API that returns GeoJson. I am not using WP-API, which is WordPress’s up and coming REST API. The reason for this is because I needed a custom type (the GeoJson) and I did not want to litter the WordPress table that stores posts, users, comments etc with a custom location type. Gps Tracker generates and deletes lots of rows in a table. I wanted to have this table separate from the WordPress system tables. It just made more sense this way so I have created custom endpoints within the Gps Tracker plugin.

I searched long and hard on trying to find out how to create a REST API with WordPress. I found a couple of plugins that do that but they were to complicated for me to figure out and certainly seemed to complicated for my needs so I spent quite some time becoming one with WordPress plugin developer documentation… And one year later, voilà. I will post a tutorial on how I created the plugin because I think it will help a lot of people. Give it a test and please feel free to ask any questions about it on this post.

Version 4.0.4 of GpsTracker has been released with support for SQLite and PostgreSQL!

I’m happy to report that the latest version of GpsTracker now supports SQLite and PostgreSQL. This is all due to Brent Fraser, a fellow developer. One of Brent’s areas of expertise is working with databases and he has put quite a lot of work into porting GpsTracker over to these two databases.

Brent has also become the second developer on GpsTracker and we are going to be exploring some new technologies to enhance GpsTracker and make it more valuable to companies. What we want to look at next is using an off the shelf gps device like this that can be permanently installed in a car or truck. We are looking for something that is cheap and reliable and can be easily purchased off of amazon. This will allow small companies to track employees, trucks and other equipment without the unnecessary cost of a cell phone. Buying a SIM and mobile plan will still be required but not having to deal with phones will greatly enhance the usability of GpsTracker for companies.

Once again, I would like to thank Brent for his hard work and welcome him to GpsTracker.

Why does Gps Tracker use GET instead of POST?

When the phone clients send gps data to the website to be stored in the database, you’ll notice that all of the clients use the Http GET method instead of POST. Most experienced developers would look at that and immediately think it was a mistake and I am one of them. GET is used to get data such as getting a list or getting user data and POST is used to add a new item to a collection or in the case of Gps Tracker, adding a new row of gps data to the database.

But there’s one important difference between GET and POST that I am taking advantage of. GET requests are sent in the URL string while POST requests are sent as part of the Http message body. I get quite a lot of requests for help in setting up Gps Tracker and the easiest way to debug setup problems is to open up a browser and send data to their website by pasting a URL like this:

https://www.websmithing.com/gpstracker/UpdateLocation.aspx?longitude=-122.0214996&latitude=47.4758847&extrainfo=0&username=momo&distance=0.012262854&date=2014-09-16%2B17%253A49%253A57&direction=0&accuracy=65&phonenumber=867-5309&eventtype=android&sessionid=0a6dfd74-df4d-466e-b1b8-23234ef57512&speed=0&locationmethod=fused

If I were trying to debug Gps Tracker using POST, I would have to use a tool like curl or wget from the command line to send the data to the website. It’s a lot more work for me to ask people to use curl or wget instead of just pasting the URL into their browser and that’s the reason why Gps Tracker uses GET.

But generally speaking, you should be using POST when you are adding new rows to a database.

Gps Tracker for WordPress plugin has been released!

It took me six months of hard work to make the Gps Tracker plugin. I had to teach myself how to create wordpress plugins and that’s no easy task. I’m very excited about this because it’s the only gps tracking plugin on wordpress. Currently, I have it set up to track only one Android cell phone. My plan is to upsell a five and ten pack here on websmithing for $29 and $49 respectively.

My next task is to set up the easy digital downloads plugin and get stripe integration going so that I can do sales directly from my website.

If you want to check out the plugin, you can download it directly from WordPress.

And from your Android phone, you can download the client from Google Play.

gps tracker for wordpress

I would like to ask any visitors and fellow developers to please help me test the new plugin. My main reason for building this plugin is that a lot of people were having difficulty installing the open source version of Gps Tracker and by creating a wordpress plugin, it takes away all that pain.

Also, wordpress now runs 22% of the world’s websites. That is a huge market and I have the only gps tracker on wordpress (did I already say that?). Anyway, I’m pleased to have this behind me, it was an immense amount of work to get to this point. Try it out and let me know how it works for you!

Version 4 of Gps Tracker has been released!

And what a whopper it is! This has been the second biggest change to Gps Tracker since it was first created. The design of the app has totally changed. It’s now using twitter bootstrap which has a style sheet that allows people to create responsive webpages. This means that it looks right on any size device such as a cell phone, tablet or desktop.

Not only that but Gps Tracker is now themed using bootswatch. This allows you to choose 17 different themes. You can switch themes by changing one single word. Here are 3 examples of the new theme, a light one:

Gps Tracker light theme

a dark one:

Gps Tracker dark theme

and a cool blue one:

Gps Tracker b;ue theme

On the clients, I have switched back to using a GET request instead of a POST request. It’s just much easier for people to troubleshoot when they can paste a URL in the browser to test out the application.

Lastly, the actual functionality of the app has changed. When you first load the app, you will see all devices displayed. The one with the red marker is the most recent gps location. When you click on a marker or select a route from the dropdown box below the map, then you will be taken to that particular route and will be able to see the route’s history on the map. Clicking on a marker will allow you to see total distance traveled and speed.

Clicking on the Auto Refresh button will update the map once a minute automatically. That will work when viewing all the devices or when viewing a single route. To get back to viewing all the devices, tap on the View All button and you’ll be back to the main view. You can see that the two views have a parent-child relationship.

If you want to see the live test version of Gps Tracker, go here:

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

If you want to try it out on your android phone, download it from google play and then check it out on the display map above. I hope you enjoy the app, it’s a significant improvement over the past design.

Is your Gps Tracker crashing?

I’m in the process of getting ready for the next major update of Gps Tracker and one of the things I’ve decided to do was to move back to using GET instead of POST with the phones. It’s just much easier to troubleshoot using GET. But, since the app in Google Play now uses GET, any old installations will not work.

I am providing here an apk file that will work with your old installations. Here is how to install it.

  1. Delete the old app from the phone.
  2. Email this apk to the user.
  3. Go to Settings > Security and check “Unknown Sources”
  4. Open the apk attachment in the email

That will reinstall the old version of the program. Here is the apk file. You may need to right click on it to download it. If you have an problem downloading it, leave a comment here and I will email it to you. I apologize for any inconvenience this may have caused you.

Nick

Gps Tracker WordPress Plugin Tutorial 1 – Map

I’ve finally begun building the Gps Tracker WordPress plugin and it is a lot of fun. The way that I’m doing this is by breaking down the functionality into separate plugins and then adding the plugins together at various stages in the build process. It’s kind of like continuous integration, for a one person team, kind of… I think it’s a really good idea to create small plugins that do just one thing, especially when you are just starting off in WordPress plugin development (like I am). I’ve already built the first three plugins, which is the map plugin, the route plugin and the database plugin. I’m currently working on the fourth plugin which is the updater plugin. The first three plugins are standalone plugins but the fourth requires two of the previous plugins (database and route) and therefor will be the first integration point.

If you are totally new to wordpress plugin development, I would like to suggest a couple of pages that will help you come up to speed. The first is “Writing a Plugin” on wordpress.org and the second is Tom McFarlin’s excellent set of tutorials.

Before we dive into the first plugin, I just want to give a brief overview of where I’m going with this, the big picture. I’m going to create a plugin that allows users to track a cell phone, store routes in a database and display the route in real time or allow the user to display previous routes using different map providers (currently set to Google, Bing and OpenStreetMaps). This is my first attempt at building a serious wordpress plugin so it will be as much a learning experience for me as it will be for you. If there are any experienced wordpress plugin developers out there who wish to correct any problems that they see, please feel free to open an issue in my github repo or comment here on any of the plugin tutorials and thank you!

Ok, on to the first tutorial. If you’d like to follow along with the code, you can download it here from github. If you have wordpress installed, you can copy the gps-tracker-map directory into your wordpress plugin directory. Then go to any page or post and add the following shortcode:

[gps-tracker-map]

and you should see a map just like this:

[gps-tracker-map]

In addition to building the map plugin, I will be setting up the structure for all future plugins in this tutorial. The first thing you see in gps-tracker-map.php is that it’s class based and that there is __construct function. This is the constructor for the class and it is always called once when the class is instantiated. Let’s take a look at it:

public function __construct() {
    register_activation_hook(__FILE__, array($this, 'activate'));
    register_deactivation_hook(__FILE__, array($this, 'deactivate'));
    register_uninstall_hook(__FILE__, array($this, 'uninstall'));
        
    // to test this plugin, add this shortcode to any page or post: [gps-tracker-map]  
    add_shortcode('gps-tracker-map', array($this,'map_shortcode'));
            
    add_action('admin_init', array($this, 'admin_init'));
    add_action('admin_menu', array($this, 'admin_menu'));
    add_filter('plugin_action_links_' . plugin_basename(__FILE__), array('Gps_Tracker_Map', 'add_action_links'));
}

The first three lines are hooks. A hook allows you to add custom code to wordpress when certain events happen. As you can see, the three events here are when you activate a plugin, deactivate it or uninstall it. When we register the activation hook, for instance, it will then call the activate function on line 29 of this plugin.

public static function activate() {
    // placeholder for future plugins
}

You’ll notice that the method doesn’t do anything yet but I am adding it now to create the structure of the plugin. The same applies to the two other hooks.

The next thing you’ll see in the constructor above is the add_shortcode function. This is another hook. When you add a shortcode to a page or a post, wordpress will replace the shortcode with code that you create in your plugin. In this case, it will call the function called map_shortcode and display and execute all of the code in that function. We’ll go into detail of what that function does in a minute. Let’s finish up looking at the constructor first. In the next line, there is an add_action function that has an admin_init hook. This event occurs when a user goes to the admin settings page of the plugin and is the first thing that is run. What happens here is that the admin_init function on line 56 of this plugin is called:

public function admin_init() {
    wp_register_style('leaflet_admin_stylesheet', plugins_url('style.css', __FILE__));
}

and what it’s doing is registering a css stylesheet for the admin settings page. The style sheet will be added later when we call wp_enqueue_style. Next we have an add_action for the admin_menu hook. This allows us to create a menu item within wordpress so that you can get to the Gps Tracker plugin settings page.

public function admin_menu() {
    add_menu_page("Gps Tracker", "Gps Tracker", 'manage_options', "gps-tracker", array(&$this, "settings_page"), plugins_url('images/satellite.png', __FILE__), 100);
}

It also puts a little satellite image in the menu so that we can be stylin’ like the rest of the WordPress menu items. You’ll notice the settings_page function name there. When a user clicks on the Settings menu link, that function will then be called.

public function settings_page() {
    wp_enqueue_style('leaflet_admin_stylesheet');
    include 'admin/admin.php';
}

Here we add the admin stylesheet to the admin settings page and then output the settings page with admin.php. Admin.php simply spits out a little bit of html at the moment. We’ll add more later.

<div class="wrap">
    <h3>Gps Tracker Settings</h3>
    <div class="wrap">
        <p>To test this plugin, add this shortcode to any page or post:</p> 
        <p>[gps-tracker-map]</p>    
    </div>
</div>

Finally, we have reached the last line of the constructor! I’ll put it here so that you don’t have to scroll up again:

add_filter('plugin_action_links_' . plugin_basename(__FILE__), array('Gps_Tracker_Map', 'add_action_links'));

You’ll notice that this is a little different than the others. Here we have an add_filter hook. The difference between add_action and add_filter is that add_action hooks are called during wordpress events like when you activate a plugin or when you publish a post, etc. add_filter hooks allow you to pass data through functions. This might occur when you are adding data to the database or sending data to the browser, for instance. Filters change data while actions allow you to do something. So what this filter does is it calls the plugin_action_links hook which allows you to add a link to the plugins page. It does this by calling this function in the plugin:

function add_action_links($links) {
    $links[] = '<a href="' . admin_url('admin.php?page=gps-tracker') . '">Settings</a>';
    return $links;
}

You’ll notice that it returns an array of links which is a clue that its being called by a filter since filters change content. And here is what it does, it adds a Settings link to the plugin page:

Settings Link on WordPress Plugin page

You may be wondering why I went to so much trouble to show you something that seems so trivial. I just wanted to point this out because so many wordpress plugins fail to include this link in their plugins and many times I have a really hard time finding their darn Settings page! I’m sure you’ve experienced that too.

Now we have finally gotten through the constructor and explained most of the code in the plugin and how the plugin is structured. Now we’ll take a look at the final function in the plugin, map_shortcode.

This function is what actually outputs the html, javascript and links to stylesheets and javascript files that we need to display the map. Most of it is fairly understandable if you have knowledge of html and javascript. It starts off with a couple of different function, wp_enqueue_script and wp_enqueue_style. This just outputs the link tag and the script tag to get our css and javascript files. This can include external files from other websites like getting the remote Google maps javascript file:

wp_enqueue_script('google_maps', '//maps.google.com/maps/api/js?v=3&sensor=false&libraries=adsense', false);

or the local leaflet css file:

wp_enqueue_style('leaflet_styles', plugins_url('javascript/leaflet-0.7.3/leaflet.css', __FILE__), false);

Remember that this function replaces the shortcode that you put into a page or a post with html and javascript, so next we create a big html string that contains both. First a div is created for our map (yes, with the style hardcoded into the div tag, we’ll change that later) and then a jQuery function is called that creates the map. Check out the leaflet quick start guide to get a better idea of what’s going on but I’ll briefly step through the code here. First we create a leaflet map object and center it to Seattle:

map = new L.map("map").setView([47.61,-122.33], 12);

You’ll notice that a lot of the code in this section looks similar to the Google maps API but with one big difference. It allows you to create and use different map providers, not only Google, and that is a very big win. There are many parts of the world where other map providers such as Bing or OpenStreetMaps has much better coverage than Google and in addition there are lots of very interesting map providers that you may have never seen before. Next we create our three layers like, for instance, the OpenStreetMap layer:

var openStreetMapsLayer = new L.TileLayer(
"//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", 
{attribution: "&copy;2014 <a href=\'http://openstreetmap.org\'>OpenStreetMap</a> contributors", maxZoom: 18}
).addTo(map);

There is a known error in leaflet that makes the map freeze up under certain conditions when the zoom buttons are clicked. They have provided a simple workaround until this is fixed and here it is:

// https://github.com/shramov/leaflet-plugins/issues/62
L.polyline([[0, 0], ]).addTo(map);

And finally we add our layers to the control in the top right hand corner of the map which allows us to select which map provider to view. Check the live map above to see what I’m talking about.

map.addControl(new L.Control.Layers({
    "Bing Maps":bingMapsLayer,
    "Google Maps":googleMapsLayer,
    "OpenStreetMaps":openStreetMapsLayer
}));

And that about covers it for our map plugin. Next on board, we’ll take a look at the route plugin which allows us to send gps data from our phone to the Gps Tracker plugin. For the full list of tutorials in this series, please visit the tutorial page here on websmithing.