Nav

NeedATaxiNow, iPhone App, PHP Server

This
application was for a client. He wanted an iPhone application that
could serve two roles. It had to allow a customer, someone you would
like to order a taxi to tap a button and have a taxi ordered as simply
as possible. The nearest taxi using the app would be informed that they
had a potential customer and decide whether to accept or allow another
taxi to pick the person up.
They also needed a centralized server that would allow for taxies and
customers to be managed and potentially allow future software to
interact with the system.

Description: NeedATaxiNow is an iPhone App that allows you to use an iPhone to order a Taxi and allows a Taxi to receive requests. I also created the PHP based server that goes along with it. The system manages the available cabs and automatically finds the nearest, notifies the customer automatically when the cab arrives.

Introduction:

This application was for a client. He wanted an iPhone application that could serve two roles. It had to allow a customer, someone you would like to order a taxi to tap a button and have a taxi ordered as simply as possible. The nearest taxi using the app would be informed that they had a potential customer and decide whether to accept or allow another taxi to pick the person up.
They also needed a centralised server that would allow for taxies and customers to be managed and potentially allow future software to interact with the system.

Design:

Since the system used an iPhone app it had to be written in Objective C. The simplest way to get the positions was with GPS, this was also the clients requested method. The main problem was how to manage the various devices, keep track of positions and provide a way for the taxis and customers to communicate. A distributed model didn't make much hence so we decided on a centralised server.
I had worked on a Linux C++ server using sockets before, I considered this briefly before deciding that PHP made more sense so I learned PHP. The database would use MySQL.

Implementation (iPhone App)

The iPhone app was repetitively straight forward. The app used a Map, GPS and a Network connection to send data to and from the PHP server. The app either functioned in customer mode where it could request a taxi. This involved getting the GPS position, connecting to the PHP server and sending a request with a unique ID and the GPS info.
In Taxi mode the App connected periodically to update its position polled the server for any messages (e.g. Request for a Taxi) upon receiving the pick-up request it would show the position on a map and give the option to pick-up the customer.

Implementation (PHP Server)

Most of the complexity was handled on the server side. PHP had been selected because of it's wide use and the client wanted the server to run on top of a standard HTTP server (Apache in this case). The server connected to a MySQL database using a table for all the devices it had contact with. The table contained a unique ID, GPS info, the mode of the device, last contacted etc.

Devices would contact the server periodically, post messages and retrieve messages. The messages could be and activation, a deactivation, a GPS update, a Pickup request, a PickupAccepted or Rejection as well as some others.

Upon receiving a pickup request the server would search for the nearest taxis, populating a list of all the nearby taxies ordered by distance. The nearest taxi to the customer would be sent a pickupRequest the taxi could reply with a pickupAccept and that Job would be entered into a table of all the jobs that have occurred. If the taxi refused or the job timed out the next in the list would be contacted and so on.

As the taxi approached it continued to notify the server where possible. As it approaches the customer the server notifies the customers app which vibrates and puts a message on the screen notifying the customer and again when it arrives.

Testing

Testing posed a number of problems mostly related to isolating the source of any problem or bug. I used XCode and instruments (part of the iOS SDK) to look for potential memory management problems and optimisations. I used two iPhone3GS for some testing and the iPhone simulator at points also. I also used wireshark to watch the actual requests going back and forth and kept and eye on the databases. To narrow down problems I added a screen available in debug mode the would allow you to set the position manualy to allow for testing and to control variables.

Conclusion

I learned a lot of PHP on this project as well a lot about testing. Testing multiple running programs at once as they talk to each other leads to a lot of complexity and the ability to narrow down and control the variables becomes extremely important.