<?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>mobile geo social &#187; jquery</title>
	<atom:link href="http://hitching.net/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://hitching.net</link>
	<description>a blog by bob hitching</description>
	<lastBuildDate>Fri, 10 Feb 2012 08:13:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Google Instant on your Maps</title>
		<link>http://hitching.net/2010/10/10/google-instant-on-your-maps/</link>
		<comments>http://hitching.net/2010/10/10/google-instant-on-your-maps/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 12:45:22 +0000</pubDate>
		<dc:creator>bob hitching</dc:creator>
				<category><![CDATA[mobile geo social]]></category>
		<category><![CDATA[geo]]></category>
		<category><![CDATA[geo-autocomplete]]></category>
		<category><![CDATA[google instant]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://hitching.net/?p=16406</guid>
		<description><![CDATA[geo-autocomplete is a jQuery extension I wrote to convert any input field on a web page into an autocomplete field that suggests locations in real-time as you type. It&#8217;s like Google Instant for your Maps. The location results are supplied &#8230; <a href="http://hitching.net/2010/10/10/google-instant-on-your-maps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://hitching.net/wp-content/uploads/2010/10/geo-autocomplete.png" alt="geo-autocomplete" title="geo-autocomplete example" width="300" height="294" style="float:left;margin-right:20px;margin-bottom:15px;border:1px solid #CCCCCC;padding:1px;" /><a href="http://code.google.com/p/geo-autocomplete/">geo-autocomplete</a> is a jQuery extension I wrote to convert any input field on a web page into an autocomplete field that suggests locations in real-time as you type. It&#8217;s like Google Instant for your Maps.</p>
<p>The location results are supplied by the <a href="http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding">Geocoding Service</a> built into <a href="http://code.google.com/apis/maps/documentation/javascript">Google Maps API v3</a>.</p>
<p>A thumbnail of each suggested location is also presented, using the <a href="http://code.google.com/apis/maps/documentation/staticmaps">Google Static Maps API v2</a>, to help you quickly choose the right location.</p>
<p>The feedback from sites using geo-autocomplete has been really positive. It has been used as a solution for users to check the spelling of foreign locations, and also as a solution to quickly <a href="http://hitching.net/2009/11/10/fast-map-re-location-using-google-static-maps-v2-geocoder">re-locate a map</a>, as seen on <a href="http://www.geome.me">GeoMeme</a>. </p>
<p>Since I wrote the first version of geo-autocomplete, about a year ago, there have been a few feature requests, and some developments in jQuery and the Google APIs that can be taken advantage of, so it’s time for an upgrade.</p>
<p>The new geo-autocomplete is built on the new <a href="http://jqueryui.com/">jQuery UI</a> framework, as a <a href="http://jqueryui.com/docs/Developer_Guide">jQuery UI Widget</a> rather than a jQuery plugin.</p>
<p>Adding geo-autocomplete to an input field is now as simple as adding one line of Javascript, plus there are some new <a href="http://code.google.com/p/geo-autocomplete/">customization options</a> available for power users.</p>
<p><a href="http://code.google.com/p/geo-autocomplete/">Here&#8217;s the code</a>, and you can play with some examples below. Start by typing location names into the input fields:</p>
<p><span id="more-16406"></span></p>
<h2>1. Basic use case; check the spelling of a location</h2>
<p>Location:<br />
<input type="text" id="demo1_location" size="50" />
<hr/>
<h2>2. Fast map re-location</h2>
<p>Location:<br />
<input type="text" id="demo2_location" size="50" />
<div id="demo2_map" style="width:400px;height:300px;margin-bottom:20px;"></div>
<hr/>
<h2>3. Restricted to Country Names within Africa</h2>
<p>Location:<br />
<input type="text" id="demo3_location" size="50" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script><br />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script><br />
<script type="text/javascript" src="http://geo-autocomplete.googlecode.com/svn/trunk/lib/jquery-ui/js/jquery-ui-1.8.5.custom.min.js"></script><br />
<script type="text/javascript" src="http://geo-autocomplete.googlecode.com/svn/trunk/ui.geo_autocomplete.js"></script><br />
<script type="text/javascript">
$().ready(function() {
	demo1();
	demo2();
	demo3();
});
function demo1() {
	$('#demo1_location').geo_autocomplete();
}
// the select function uses the viewport of the chosen location to relocate the map
function demo2() {
    var map = new google.maps.Map(document.getElementById("demo2_map"), { mapTypeId: google.maps.MapTypeId.ROADMAP });
	$('#demo2_location').geo_autocomplete({
		select: function(_event, _ui) {
			if (_ui.item.viewport) map.fitBounds(_ui.item.viewport);
		}
	});
}
function demo3() {
	$('#demo3_location').geo_autocomplete({
		geocoder_region: 'Africa',
		geocoder_types: 'country',
		mapheight: 100, mapwidth: 200, maptype: 'hybrid'
	});
}
</script></p>
<link type="text/css" href="http://geo-autocomplete.googlecode.com/svn/trunk/lib/jquery-ui/css/ui-lightness/jquery-ui-1.8.5.custom.css" rel="stylesheet" />
<style type="text/css">
.ui-autocomplete { overflow-y: auto; width:300px; }
* html .ui-autocomplete { /* IE max- */height: expression( this.scrollHeight > 320 ? "320px" : "auto" ); }
.ui-autocomplete { max-height: 320px; }
.ui-autocomplete li { font-size:10pt; }
</style>
]]></content:encoded>
			<wfw:commentRss>http://hitching.net/2010/10/10/google-instant-on-your-maps/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Fast map re-location using Google Static Maps v2 + geocoder</title>
		<link>http://hitching.net/2009/11/10/fast-map-re-location-using-google-static-maps-v2-geocoder/</link>
		<comments>http://hitching.net/2009/11/10/fast-map-re-location-using-google-static-maps-v2-geocoder/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 01:00:00 +0000</pubDate>
		<dc:creator>bob hitching</dc:creator>
				<category><![CDATA[mobile geo social]]></category>
		<category><![CDATA[geo]]></category>
		<category><![CDATA[geo-autocomplete]]></category>
		<category><![CDATA[geocode]]></category>
		<category><![CDATA[geomeme]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[static maps]]></category>

		<guid isPermaLink="false">http://hitching.net/?p=15938</guid>
		<description><![CDATA[GeoMeme is a pet project of mine. It&#8217;s a web app, and also a mobile web app for iPhone and Android, that measures real-time local twitter trends. Visitors to GeoMeme choose a location on the map, and two search terms &#8230; <a href="http://hitching.net/2009/11/10/fast-map-re-location-using-google-static-maps-v2-geocoder/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.geome.me/">GeoMeme</a> is a pet project of mine. It&#8217;s a web app, and also a mobile web app for iPhone and Android, that measures real-time local twitter trends.</p>
<p>Visitors to GeoMeme choose a location on the map, and two search terms to compare. GeoMeme then measures and compares the number of matching tweets within the bounds of the map, based on public data from a number of mobile twitter apps.</p>
<p>As an example, GeoMeme can work out that <a href="http://www.geome.me/Rebr1">&#8216;District 9&#8242; beats &#8216;Inglorious Basterds&#8217; in Manhattan</a>.</p>
<p>As well as offering users the normal pan and zoom controls to move the map around, GeoMeme also introduces an innovative geo-autocomplete control which is powered by the geocoder service from <a href="http://code.google.com/apis/maps/documentation/v3/">Google Maps v3 API</a> and the new <a href="http://code.google.com/apis/maps/documentation/staticmaps/">Static Maps v2 API</a>.</p>
<p><img style="width: 301px; height: 314px; border: 1px solid #cccccc; padding: 1px;" src="http://www.geome.me/i/help1.png" /></p>
<p>This blog post shares some details of how the geo-autocomplete control works, and offers some code so you can build your own geo-autocomplete controls.</p>
<p><strong>1. Based on a partial location typed by the user, obtain a list of possible matching locations</strong>:</p>
<p>If the user has already typed &#8216;San&#8217; into a form field, we can obtain a list of possible matching locations by passing this partial location to the geocoder service from Google Maps v3 API, as follows:</p>
<p><span id="more-15938"></span></p>
<pre class="brush: jscript; title: ;">
var partial_location = document.getElementById(&quot;location&quot;).value;
var geocoder = new google.maps.Geocoder();

geocoder.geocode({'address': partial_location}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        document.getElementById(&quot;results&quot;).innerHTML = '';
        for (var i = 0; i &lt; results.length; i++) {
            showResult(results[i]);
        }
    } else {
        document.getElementById(&quot;results&quot;).innerHTML = 'Geocode was not successful for the following reason: ' + status;
    }
});

function showResult(result) {
    document.getElementById(&quot;results&quot;).innerHTML += 'It could be: ' + result.formatted_address + '&lt;br/&gt;';
}
</pre>
<p><strong>2. Decorate these possible matching locations with a Static Maps thumbnail to help the user choose the right one:</strong></p>
<p>The geocoder returns more than just a formatted address. The full response is a JSON object of the following form:</p>
<pre class="brush: jscript; title: ;">
results[]: {
    types[]: google.maps.GeocoderLocationType,
    formatted_address: String,
    address_components[]: {
        short_name: String,
        long_name: String,
        types[]: String
    },
    geometry: {
        location: LatLng,
        location_type: String,
        viewport: LatLngBounds,
        bounds: LatLngBounds
    }
}
</pre>
<p><strong style="font-family: Courier New;">geometry.viewport</strong> represents the recommended viewport for each returned result, from which we can derive the required Static Maps URL, as follows:</p>
<pre class="brush: jscript; title: ;">
function showResult(result) {
    var src = 'http://maps.google.com/maps/api/staticmap';

    // the visible parameter specifies one or more locations
    // to show on the map. so we need to specify the south-west
    // and north-east corners of geometry.viewport
    src += '?visible=' + result.geometry.viewport.getSouthWest().toUrlValue() + '|' + result.geometry.viewport.getNorthEast().toUrlValue();

    // other parameters as per http://code.google.com/apis/maps/documentation/staticmaps/#URL_Parameters
    src += '&amp;size=100x100&amp;maptype=terrain&amp;key=YOUR_API_KEY&amp;sensor=false';

    document.getElementById(&quot;results&quot;).innerHTML += '&lt;img src=&quot;' + src + '&quot; /&gt; ' + result.formatted_address + '&lt;br/&gt;';
}
</pre>
<p>Working out the required Static Maps URL is now a much simpler task with v2 of the Static Maps API, because there is no longer any need to manually calculate a zoom level or latitude / longitude span values.</p>
<p>You can see this working on <a href="http://www.geome.me/Q9zbo">GeoMeme</a> by clicking on the location control at the top of the screen and entering a partial location. When you choose from the list of possible matches, the main map is moved to that location, providing a refreshingly quick way for users to re-position the map.</p>
<p>You can also download a hello world example <a href="http://code.google.com/p/geo-autocomplete/">here</a>, built as a jQuery plugin to work with a modified version of the excellent Autocomplete plugin:</p>
<p><iframe src="http://geo-autocomplete.googlecode.com/svn/trunk/demo/index.html" width="550" height="480" frameborder="0"><br />
<a href="http://geo-autocomplete.googlecode.com/svn/trunk/demo/index.html"><img src="http://geo-autocomplete.googlecode.com/svn/trunk/demo/screenshot.png" /></a></iframe></p>
<p>Using this <a href="http://code.google.com/p/geo-autocomplete/">geo-autocomplete</a> plugin is recommended because it includes a number of features which protect the geocoder service from being hit too often. Including; waiting for keystrokes to stop before sending a request to the geocoder, waiting for a minimum number of characters to by typed, and caching geocoder responses to avoid duplicate requests. Options are also available to set the size and maptype of the Static Map thumbnails.</p>
<p><b>Update: geo-autocomplete has been rebuilt upon the jQuery UI framework, as a UI Widget rather than a jQuery plugin, with more powerful options for customization.</b></p>
<p><em>This post is one of a <a href="http://googlegeodevelopers.blogspot.com/2009/11/geolocation-mobile-web-apps-geo.html">series</a> that aims to share some of the technology innovation that can be found in <a href="http://www.geome.me/">GeoMeme</a>. Other posts cover topics such as <a href="http://hitching.net/2009/11/10/location-aware-mobile-web-apps-using-google-maps-v3-geolocation/">location-aware mobile web apps</a> using Google Maps v3, and <a href="http://hitching.net/2009/11/10/scalable-fast-accurate-geo-apps-using-google-app-engine-geohash-faultline-correction/">scalable geo apps</a> using Google App Engine.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://hitching.net/2009/11/10/fast-map-re-location-using-google-static-maps-v2-geocoder/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

