Get On Your Byke!
2010-06-03
nakdeveloper
While we've been busy organising the Location Wild competition that is running this week, Peter took some time out to sample what life was like for the competition participants by building his own location-based app.
Unlike the competition participants, Peter spent only a couple of hours on his app, but it makes a good case-study for high-speed development using the NakdReality platform. If you're curious, try the app at Byke.mobi
Now over to Peter:
Byke.mobi created using NakdReality's API
Using NakdReality's API, I created the following app in just a few hours: "Byke" (http://byke.mobi) is intended to allow people to rent out their temporarily unused bikes to travellers nearby, and it runs anywhere in the world. It works across modern iPhone, Android, Blackberry, Nokia phones, on the Desktop Web, and Layar Augmented Reality platforms.
Government departments in the UK and Canada are currently spending large sums of money in purchasing custom built bikes for rental, but could there be a different solution that scales up more easily? We looked at the problem from a different angle: there are millions of unused bikes sitting in back gardens. Why not put them to good use? All that we need to know is their latitude and longitude, and we can connect local travellers to the bikes using NakdReality's location search. The Byke service engages everyone from kids to grandparents. Have a spare bike? Put it up for rental, and you can be earning a few extra dollars each day.
If you're travelling into another city, rent a bike for the day starting near the station, instead of taking a taxi. Costs are fixed per country, and are cheaper than taxis - US $5 in the US for a day, which is comparable to taking public transport, but you have complete freedom to go where you like. The only stipulation is that you take the bike back to where you found it originally. There is a deposit you have to pay first to safeguard the return of the bike, and this is handled through the neutral website and returned in full after return of the bike.
So, how did I build this app so quickly? NakdReality.com provides all of the leg-work in making the location search operate at the backend, while owlz.org and the Layar AR application allow an instant user-interface. It was really just a matter of following the API. And, of course, if this Byke app becomes wildly successful, NakdReality will scale out (via Amazon's cloud infrastructure) to handle the demand.
Here's some of the PHP code I used for this app:
//Byke.mobi -- coded at pace!
public function read_nakd_id_xml($response)
{
$xml = simplexml_load_string($response);
$xml->getName();
$id = false;
foreach($xml->children() as $child)
{
if($child->getName() == 'ids') {
$id = $child;
}
}
return $id;
}
//See: http://netevil.org/blog/2006/nov/http-post-from-php-without-curl
//for function do_post_request($url, $data, $optional_headers = null)
$text_data = "\"var_title\",\"var_line_2\",\"var_line_3\",\"var_line_4\", \
\"dec_latitude\",\"dec_longitude\",\"var_image\",\"var_actions_label_1\", \
\"var_actions_uri_1\"
\"$bike_name\",\"$price\",\"Times: $availability\",\"$size inches frame\", \
$lat,$lon,\"$image_url\",\"Rent Bike\",\"" . RETURN_URL . \
"new_customer.php?bike_id=" . mysql_insert_id() . "\"";
//Call NakdReality and do an insert
$response = $this->do_post_request("http://nakdreality.com/insert",
"user=[MYEMAIL]&layer=byke&pass=[MYPASS]&data=" . $text_data);
//Check the response
if($nakd_id = $this->read_nakd_id_xml($response)) {
//Put the nakd id back into our database
$sql = "UPDATE tbl_bike SET int_nakd_id = $nakd_id,
var_photo = '$image_url'
WHERE int_bike_id = " . mysql_insert_id();
$res = mysql_query($sql) or die("Unable to execute query $sql " .
mysql_error());
} else {
echo "Error inserting into NakdReality. Please try again soon.";
}
An important point is that we need to save the NakdReality ID returned from the insert back into our database. This is used when we run a delete statement on it in future when the data is edited.
The whole process was straightforward: we could test in the NakdReality GUI and see our data being added after we ran our own inserts, and then we could clear the data when we were ready to take it live.
Because the NakdReality data format is automatically visible in the Open Web Location browZer (owlz.org) along with Layar augmented reality browser (layar.com), it instantly becomes searchable on a wide array of phones and on the web.
This is just one example of what location searches can do, and NakdReality is making it considerably easier to put an application like this together.
