<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BritishIdeas &#187; Text Messaging</title>
	<atom:link href="http://www.britishideas.com/tag/text-messaging/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.britishideas.com</link>
	<description>Interesting Tech Projects</description>
	<lastBuildDate>Sun, 23 Oct 2011 20:05:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter + Google Maps + Text Messaging Mashup</title>
		<link>http://www.britishideas.com/2009/08/16/twitter-google-maps-test-messaging-mashup/</link>
		<comments>http://www.britishideas.com/2009/08/16/twitter-google-maps-test-messaging-mashup/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 17:55:05 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Mapping]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Text Messaging]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.britishideas.com/2009/08/16/twitter-google-maps-test-messaging-mashup/</guid>
		<description><![CDATA[I am planning a road trip and thought about using Twitter to send updates from the road. As my phone doesn&#8217;t have internet access and emailing using the Samsung interface is difficult, I would be restricted to text messaging. However I really wanted a way to post tweets with a link to a map showing]]></description>
			<content:encoded><![CDATA[<p>I am planning a road trip and thought about using <a href="http://twitter.com" target="_blank">Twitter</a> to send updates from the road. As my phone doesn&#8217;t have internet access and emailing using the Samsung interface is difficult, I would be restricted to text messaging. However I really wanted a way to post tweets with a link to a map showing my approximate location. Ideally it would allow vague descriptions such as &#8220;Euclid and Stone, Tucson&#8221; as well as latitude and longitude, e.g. &#8220;N 32. 16.123 W 110 18.654&#8243;.</p>
<p>Surprisingly a search turned up very few options.  There is, however, a service that already does everything I want, and it&#8217;s called <a href="http://geo.ly" target="_blank">Geo.ly</a>. So why not use it I hear you ask? Well there are two large problems. Firstly the twitter interface doesn&#8217;t seem to be working right now and appears to have reliability problems. Secondly about 20% of the time the service will give you a URL to a map that doesn&#8217;t work &#8211; all you see is a blank page.</p>
<p>After a bit more fruitless searching I sat down and wrote my own PHP code that pulls everything together. Here is how it works.</p>
<p>There is a free text messaging service called <a href="http://www.textmarks.com" target="_blank">TextMarks</a> that converts text messaging to/from HTTP requests and responses. All that&#8217;s needed to send and receive text messages is to write a PHP (or CGI) script and put it on a web server somewhere. I tried it and it really is a piece of cake.</p>
<p>Next was to convert the text description of a location into latitude and longitude. For this Google provides a free <a href="http://code.google.com/apis/maps/documentation/geocoding/" target="_blank">geocoding</a> system, providing that the results are shown on a Google map. After a bit more work I had this working and it can accept a wide variety of input descriptions. For example the ones I listed above plus things like &#8220;Grand Canyon National Park&#8221;. Perfect.</p>
<p>The final piece of the puzzle was to automatically post the tweet with the location of the Google map using the <a href="http://apiwiki.twitter.com/" target="_blank">Twitter API</a>. I found that Twitter automatically shortens URLs in tweets using the <a href="http://bit.ly" target="_blank">bit.ly</a> service.</p>
<p>So now I can send a text message with a rough description of my location, the location is converted to coordinates, a tweet is generated with a link to the map and a confirmation text message is sent back to my phone. This typically takes about 15 seconds. Nice!</p>
<p>Below is the PHP script. Use at your own risk. To install:</p>
<ol>
<li>Copy to somewhere on your webserver</li>
<li>Go to TextMarks and create a new TextMark for your service</li>
<li>Create a TextMarks account and edit the configuration. Disable messaging and any public options for your TextMark &#8211; after all you don&#8217;t want other people posting locations to your twitter account.</li>
<li>Edit the script and enter your Twitter username and password. Also enter your <a href="http://code.google.com/apis/maps/signup.html" target="_blank">Google Maps API key</a> (which is free).</li>
</ol>
<p>Note that there is no authentication used in the script. This is because the script is not linked to, uses an obscure name (not twitter.php, which is just an example name), and the TextMark is private. However, if desired, the TextMarks service can pass the phone number to the script allowing for only specific phones to use the system.</p>
<p>A public version would, of course, need more input checking, user authentication, etc.<br />
<code><br />
&lt;?php<br />
// script to take a location description from a text message,<br />
// generate a URL to a map and then tweet the URL<br />
// the result is returned as a text message<br />
</code></p>
<p><code><br />
// (C) Copyright Andrew Ayre, 2009<br />
// andy at britishideas dot com<br />
</code></p>
<p><code><br />
// call from TextMarks using something like:<br />
// http://www.mydomain.com/twitter.php?args=\0<br />
</code></p>
<p><code><br />
// This program is free software; you can redistribute it and/or<br />
// modify it under the terms of the GNU General Public License<br />
// as published by the Free Software Foundation; either version 2<br />
// of the License, or (at your option) any later version.<br />
</code></p>
<p><code><br />
// This program is distributed in the hope that it will be useful,<br />
// but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br />
// GNU General Public License for more details.<br />
// You should have received a copy of the GNU General Public License<br />
// along with this program; if not, write to the Free Software<br />
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.<br />
// See: http://www.gnu.org/licenses/gpl-2.0.html<br />
</code></p>
<p><code><br />
// twitter username and password<br />
$twitter_username = 'myusername';<br />
$twitter_password = 'mypassword';<br />
// API key for Google Maps<br />
$google_mapsapikey = 'myapikey';<br />
</code></p>
<p><code><br />
// max time to wait for tweet responses from twitter in seconds<br />
$twitter_timeout = 30;<br />
// max time to wait for Google geocoding service in seconds<br />
$google_timeout = 30;<br />
</code></p>
<p><code><br />
// get text message contents<br />
$args = $_GET['args'];<br />
// encode<br />
$args = urlencode($args);<br />
</code></p>
<p><code><br />
// geocode input<br />
$req = curl_init("http://maps.google.com/maps/geo?q=$args&amp;output=json&amp;oe=utf8&amp;sensor=false&amp;key=$google_mapsapikey");<br />
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);<br />
curl_setopt($req, CURLOPT_CONNECTTIMEOUT, $google_timeout);<br />
$output = curl_exec($req);<br />
curl_close($req);<br />
</code></p>
<p><code><br />
// parse geocoding result<br />
$result = json_decode($output, true);<br />
if ($result == NULL) {<br />
echo "Geocoding failed";<br />
return;<br />
}<br />
</code></p>
<p><code><br />
// get address and coordinates<br />
$address = $result['Placemark'][0]['address'];<br />
$lon = $result['Placemark'][0]['Point']['coordinates'][0];<br />
$lat = $result['Placemark'][0]['Point']['coordinates'][1];<br />
</code></p>
<p><code><br />
// construct Google URL<br />
$mapurl = urlencode("http://maps.google.com/maps?q=$lat+$lon&amp;mrt=yp");<br />
</code></p>
<p><code><br />
// send to twitter - based on<br />
// http://morethanseven.net/2007/01/20/posting-to-twitter-using-php/<br />
$tweet = "I am somewhere near $mapurl";<br />
$req = curl_init('https://twitter.com/statuses/update.xml');<br />
curl_setopt($req, CURLOPT_CONNECTTIMEOUT, $twitter_timeout);<br />
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);<br />
curl_setopt($req, CURLOPT_POST, true);<br />
curl_setopt($req, CURLOPT_POSTFIELDS, "status=$tweet");<br />
curl_setopt($req, CURLOPT_USERPWD, "$twitter_username:$twitter_password");<br />
$output = curl_exec($req);<br />
curl_close($req);<br />
</code></p>
<p><code><br />
// return result via text message<br />
if (empty($output))<br />
{<br />
echo "Failed: $address, $lat, $lon";<br />
} else {<br />
echo "Tweeted: $address, $lat, $lon";<br />
}<br />
?&gt;<br />
</code></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d129').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark to:</em></strong></a>
<br />
<div class="d129" style="overflow:hidden">
<br />
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d129').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d129').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://www.britishideas.com/2009/08/16/twitter-google-maps-test-messaging-mashup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

