<?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>Latest-Tutorial &#187; Aspx.NET Tutorials</title>
	<atom:link href="http://latest-tutorial.com/category/aspx-net-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://latest-tutorial.com</link>
	<description>Best Tutorials for Beginners of Java,Android,JavaScript,Asp.net,Objective C,C-Sharp and many other topics.We have experts tutorial material against these topics.</description>
	<lastBuildDate>Wed, 22 May 2013 08:39:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Google Map Geocoding Tutorial with Example</title>
		<link>http://latest-tutorial.com/2013/03/22/google-map-geocoding-tutorial-with-example/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=google-map-geocoding-tutorial-with-example</link>
		<comments>http://latest-tutorial.com/2013/03/22/google-map-geocoding-tutorial-with-example/#comments</comments>
		<pubDate>Fri, 22 Mar 2013 07:18:50 +0000</pubDate>
		<dc:creator>Zeeshan Akhter</dc:creator>
				<category><![CDATA[Android Tutorials]]></category>
		<category><![CDATA[Aspx.NET Posts]]></category>
		<category><![CDATA[Aspx.NET Tutorials]]></category>
		<category><![CDATA[Courses]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[GAME]]></category>
		<category><![CDATA[Java Posts]]></category>
		<category><![CDATA[Java Tutorials]]></category>
		<category><![CDATA[JavaScript Posts]]></category>
		<category><![CDATA[JavaScript Tutorials]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Random Posts]]></category>

		<guid isPermaLink="false">http://latest-tutorial.com/?p=2401</guid>
		<description><![CDATA[Google Map API has been a great way to show geographical information on web. A lot of mashup tools like this, have been created around Google Maps to show a wide variety of data. In my previous article about Introduction to Google Maps API, I had described basic APIs to integrate Google Map in your [...]]]></description>
				<content:encoded><![CDATA[<div class="page-restrict-output"><div style="padding-left:5px; padding-right:5px; padding-bottom:5px; padding-top:5px; margin-left:auto; margin-right:auto; ">
<script type="text/javascript"><!--
google_ad_client = "pub-1265735558479661";
google_ad_width = 468;
google_ad_height = 60;
google_color_border = "FFFFFF";
google_color_link = "E895CC";
google_color_text = "000000";
google_color_bg = "FFFFFF";
google_color_url = "0066CC";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><img class="alignright" title="google-map-reverse-geocoding" alt="google-map-reverse-geocoding" src="http://i2.wp.com/latest-tutorial.com/wp-content/uploads/2013/03/google-map-reverse-geocoding.png?resize=208%2C174" data-recalc-dims="1" /><strong>Google Map API</strong> has been a great way to show geographical information on web. A lot of <a href="http://viralpatel.net/blogs/google-maps-and-twitter-mashup-show-uk-snowfall-google-map-twitter-mashup/"><strong>mashup tools like this</strong></a>, have been created around <strong>Google Maps</strong> to show a wide variety of data. In my previous article about <a href="http://viralpatel.net/blogs/introduction-to-google-maps/"><strong>Introduction to Google Maps API</strong></a>, I had described basic APIs to integrate Google Map in your webpage. In this small article we will discuss a great feature of Google Maps API that can be used to locate any City/Country/Place on Map. This is called <strong>Geocoding</strong>.<br />
<a href="http://gan.doubleclick.net/gan_click?lid=41000613802549601&#038;pubid=21000000000370691&#038;lsrc=289"><img src="http://latest-tutorial.com/wp-content/uploads/2013/03/gan_impressionlid41000613802549601pubid21000000000370691lsrc289" border=0 alt="20756_Free Shipping Plus VIP Exclusive Perks &amp; Savings with code: CX13J027"/></a><br />
Google Maps API provides a wonderful API called Geocoding API that enables you to fetch any location and pin point it on Google Map. <code>GClientGeocoder</code> is the class that we use to get the geocoder that get us the location. We will use <strong>getLatLng()</strong> method to get latitude/longitude of any location.<br />
Check the following code.</p>
<div>
<div id="highlighter_394306">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>var</code> <code>place =  </code><code>"New York"</code><code>;</code></div>
<div><code>geocoder = </code><code>new</code> <code>GClientGeocoder();</code></div>
<div><code>geocoder.getLatLng(place, </code><code>function</code><code>(point) {</code></div>
<div><code>    </code><code>if</code> <code>(!point) {</code></div>
<div><code>        </code><code>alert(place + </code><code>" not found"</code><code>);</code></div>
<div><code>    </code><code>} </code><code>else</code> <code>{</code></div>
<div><code>        </code><code>var</code> <code>info = </code><code>"&lt;h3&gt;"</code><code>+place+</code><code>"&lt;/h3&gt;Latitude: "</code><code>+point.y+</code><code>"  Longitude:"</code><code>+point.x;</code></div>
<div><code>        </code><code>var</code> <code>marker = </code><code>new</code> <code>GMarker(point);</code></div>
<div><code>        </code><code>map.addOverlay(marker);</code></div>
<div><code>        </code><code>marker.openInfoWindowHtml(info);</code></div>
<div><code>    </code><code>}</code></div>
<div><code>});</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>In above code snippet we passed string “New York” and a handler function to getLatLng() method of GClientGeocoder. GClientGeocoder class will call google server for the location and when it gets the result, it pass the result to the handler function that we specified. Thus handler function will get point (GPoint) object from which we can get the latitude and longitude of location. In above code we have created a marker and placed it on the map.</p>
<h2>Online Demo</h2>
<p><a href="http://viralpatel.net/blogs/demo/google-map-reverse-geocoding.html" target="_new"><strong>Google Map Reverse Geocode Example</strong></a></p>
<script type="text/javascript"><!--
google_ad_client = "pub-1265735558479661";
google_ad_width = 468;
google_ad_height = 60;
google_color_border = "FFFFFF";
google_color_link = "E895CC";
google_color_text = "000000";
google_color_bg = "FFFFFF";
google_color_url = "0066CC";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>]]></content:encoded>
			<wfw:commentRss>http://latest-tutorial.com/2013/03/22/google-map-geocoding-tutorial-with-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create your own Search Engine(Interface) using Google Custom Search API</title>
		<link>http://latest-tutorial.com/2013/03/22/create-your-own-search-engineinterface-using-google-custom-search-api-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=create-your-own-search-engineinterface-using-google-custom-search-api-2</link>
		<comments>http://latest-tutorial.com/2013/03/22/create-your-own-search-engineinterface-using-google-custom-search-api-2/#comments</comments>
		<pubDate>Fri, 22 Mar 2013 07:14:24 +0000</pubDate>
		<dc:creator>Zeeshan Akhter</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Android Posts]]></category>
		<category><![CDATA[Android Tutorials]]></category>
		<category><![CDATA[Aspx.NET Posts]]></category>
		<category><![CDATA[Aspx.NET Tutorials]]></category>
		<category><![CDATA[Courses]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[GAME]]></category>
		<category><![CDATA[Java Posts]]></category>
		<category><![CDATA[Java Tutorials]]></category>
		<category><![CDATA[JavaScript Posts]]></category>
		<category><![CDATA[JavaScript Tutorials]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Random Posts]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Create your own Search Engine]]></category>

		<guid isPermaLink="false">http://latest-tutorial.com/?p=2391</guid>
		<description><![CDATA[Google Custom Search API are wonderful tools to create some awesome search engine like tools. Also if you want to add a search option to your website and customize the look and feel of your search results, Google Custom Search API serve best to you. Ring in Spring with Stunning Lingerie from Journelle and get [...]]]></description>
				<content:encoded><![CDATA[<div class="page-restrict-output"><p><img class="alignright" title="google-api-real-time-search" alt="google-api-real-time-search" src="http://i2.wp.com/latest-tutorial.com/wp-content/uploads/2013/03/google-api-real-time-search.png?resize=325%2C101" data-recalc-dims="1" /><br />
<a class="zem_slink" title="Google Custom Search" href="http://www.google.com/cse" target="_blank" rel="homepage">Google Custom Search</a> <a class="zem_slink" title="Application programming interface" href="http://en.wikipedia.org/wiki/Application_programming_interface" target="_blank" rel="wikipedia">API</a> are wonderful tools to create some awesome search engine like tools. Also if you want to add a search option to your website and customize the look and feel of your search results, Google Custom Search API serve best to you.<br />
<a href="http://gan.doubleclick.net/gan_click?lid=41000613802586524&#038;pubid=21000000000370691&#038;lsrc=289">Ring in Spring with Stunning Lingerie from Journelle and get $25 OFF purchases of $200 or more! Use promo code: SPRING200. Offer valid 2/22/13-4/30/13. Shop Now</a></p>
<p>I have created a Real Time Search engine (I call it real time as it search as you type). I am really impressed by the speed/response of Google Search API.</p>
<p><center></p>
<h3><a href="http://viralpatel.net/realtime/" target="_new">DEMO</a></h3>
<p></center><br />
<img title="google-search-technology" alt="google-search-technology" src="http://i0.wp.com/latest-tutorial.com/wp-content/uploads/2013/03/google-search-technology.png?resize=473%2C330" data-recalc-dims="1" /></p>
<p><center></p>
<h3><a href="http://viralpatel.net/realtime/" target="_new">DEMO</a></h3>
<p></center></p>
<h2>The Code</h2>
<p>I will show the code for one of the search api that I implemented in demo page. Let us see how to implement <a class="zem_slink" title="World Wide Web" href="http://maps.google.com/maps?ll=46.2325,6.045&amp;spn=0.01,0.01&amp;q=46.2325,6.045 (World%20Wide%20Web)&amp;t=h" target="_blank" rel="geolocation">Web</a> Search API.</p>
<h3>Step 1: Generate Google Search API Key and Include <a class="zem_slink" title="JavaScript" href="http://en.wikipedia.org/wiki/JavaScript" target="_blank" rel="wikipedia">JavaScript</a></h3>
<p>In order to use Google Search API, you have to first generate a Key for you. Go to following page and signup your self for the Key.<br />
<a href="http://code.google.com/apis/ajaxsearch/signup.html" target="_new">Sign up for Google API Key</a></p>
<p>Next step is to include the Google Search API javascript. Don’t forget to mention your key in the below code.</p>
<div>
<div id="highlighter_716674">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>&lt;script src=</code><code>"http://www.google.com/jsapi?key=YOURKEY"</code> <code>type=</code><code>"text/javascript"</code><code>&gt;&lt;/script&gt;</code></div>
<div><code>&lt;script type=</code><code>"text/javascript"</code><code>&gt;</code></div>
<div><code>    </code><code>google.load(</code><code>'search'</code><code>, </code><code>'1'</code><code>);</code></div>
<div><code>&lt;/script&gt;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p><a href="http://gan.doubleclick.net/gan_click?lid=41000613802561287&#038;pubid=21000000000370691&#038;lsrc=289">Primary</a></p>
<h3>Step 2: Add HTML Container for Web Search</h3>
<p>We will create a textbox and a button that will take input for search. And a <a class="zem_slink" title="Span and div" href="http://en.wikipedia.org/wiki/Span_and_div" target="_blank" rel="wikipedia">DIV</a> that will be populated by results:</p>
<div>
<div id="highlighter_821250">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>&lt;</code><code>input</code> <code>type</code><code>=</code><code>"text"</code> <code>title</code><code>=</code><code>"Real Time Search"</code> <code>name</code><code>=</code><code>"searchbox"</code><code>/&gt;</code></div>
<div><code>&lt;</code><code>input</code> <code>type</code><code>=</code><code>"button"</code> <code>id</code><code>=</code><code>"searchbtn"</code> <code>value</code><code>=</code><code>"Search"</code> <code>onclick</code><code>=</code><code>"search(searchbox.value)"</code><code>/&gt;</code></div>
<div></div>
<div><code>&lt;</code><code>div</code> <code>class</code><code>=</code><code>"data"</code> <code>id</code><code>=</code><code>"web-content"</code><code>&gt;&lt;/</code><code>div</code><code>&gt;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>When user will write a query and push <a class="zem_slink" title="Search box" href="http://en.wikipedia.org/wiki/Search_box" target="_blank" rel="wikipedia">Search button</a>, a request will be made to Google Search using Custom Search API and the results are fetched. These results are then copied into the DIV.</p>
<h3>Step 3: JavaScript to call Google Search API</h3>
<p>We will use following JavaScript to call the Google Search API and copy the results in our container DIV.<br />
The code in plain english is:<br />
1. Create an object to connect <a class="zem_slink" title="Google Search" href="http://Google.com" target="_blank" rel="homepage">Google Web search</a> using class <code>google.search.WebSearch</code>.<br />
2. Set a <a class="zem_slink" title="Callback (computer programming)" href="http://en.wikipedia.org/wiki/Callback_%28computer_programming%29" target="_blank" rel="wikipedia">callback function</a> that will get call once the results for the search are fetched.<br />
3. Call the <code>execute()</code> method with search query as argument.<br />
4. In callback function, iterate through the results and copy it to container DIV.</p>
<div>
<div id="highlighter_308221">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>
<div><code>var</code> <code><a class="zem_slink" title="Web search engine" href="http://en.wikipedia.org/wiki/Web_search_engine" target="_blank" rel="wikipedia">webSearch</a>;</code></div>
<div><code>webSearch = </code><code>new</code> <code>google.search.WebSearch();</code></div>
<div><code>webSearch.setSearchCompleteCallback(</code><code>this</code><code>, webSearchComplete, [webSearch]);</code></div>
<div></div>
<div><code>function</code> <code>webSearchComplete (searcher, searchNum) {</code></div>
<div><code>    </code><code>var</code> <code>contentDiv = document.getElementById(</code><code>'web-content'</code><code>);</code></div>
<div><code>    </code><code>contentDiv.innerHTML = </code><code>''</code><code>;</code></div>
<div><code>    </code><code>var</code> <code>results = searcher.results;</code></div>
<div></div>
<div><code>    </code><code>var</code> <code>newResultsDiv = document.createElement(</code><code>'div'</code><code>);</code></div>
<div><code>    </code><code>newResultsDiv.id = </code><code>'web-content'</code><code>;</code></div>
<div><code>    </code><code>for</code> <code>(</code><code>var</code> <code>i = 0; i &lt; results.length; i++) {</code></div>
<div><code>      </code><code>var</code> <code>result = results[i];</code></div>
<div></div>
<div><code>      </code><code>var</code> <code>resultHTML = </code><code>'&lt;div&gt;'</code><code>;</code></div>
<div><code>      </code><code>resultHTML += </code><code>'&lt;a href="'</code> <code>+ result.unescapedUrl + </code><code>'" target="_blank"&gt;&lt;b&gt;'</code> <code>+</code></div>
<div><code>                        </code><code>result.titleNoFormatting + </code><code>'&lt;/b&gt;&lt;/a&gt;&lt;br/&gt;'</code> <code>+</code></div>
<div><code>                        </code><code>result.content +</code></div>
<div><code>                        </code><code>'&lt;div/&gt;'</code><code>;</code></div>
<div><code>      </code><code>newResultsDiv.innerHTML += resultHTML;</code></div>
<div><code>    </code><code>}</code></div>
<div><code>    </code><code>contentDiv.appendChild(newResultsDiv);</code></div>
<div><code>}</code></div>
<div></div>
<div><code>function</code> <code>search(query) {</code></div>
<div><code>    </code><code>webSearch.execute(query);</code></div>
<div><code>}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3><a href="http://viralpatel.net/realtime/" target="_new">Click for Online Demo</a></h3>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul zemanta-article-ul-image" style="margin: 0; padding: 0; overflow: hidden;">
<li class="zemanta-article-ul-li-image zemanta-article-ul-li" style="padding: 0; background: none; list-style: none; display: block; float: left; vertical-align: top; text-align: left; width: 84px; font-size: 11px; margin: 2px 10px 10px 2px;"><a style="box-shadow: 0px 0px 4px #999; padding: 2px; display: block; border-radius: 2px; text-decoration: none;" href="http://www.freetech4teachers.com/2013/03/how-to-create-your-own-search-engine.html" target="_blank"><img style="padding: 0; margin: 0; border: 0; display: block; width: 80px; max-width: 100%;" alt="" src="http://i0.wp.com/latest-tutorial.com/wp-content/uploads/2013/03/149266741_80_80.jpg" data-recalc-dims="1" /></a><a style="display: block; overflow: hidden; text-decoration: none; line-height: 12pt; height: 80px; padding: 5px 2px 0 2px;" href="http://www.freetech4teachers.com/2013/03/how-to-create-your-own-search-engine.html" target="_blank">How to Create Your Own Search Engine</a></li>
<li class="zemanta-article-ul-li-image zemanta-article-ul-li" style="padding: 0; background: none; list-style: none; display: block; float: left; vertical-align: top; text-align: left; width: 84px; font-size: 11px; margin: 2px 10px 10px 2px;"><a style="box-shadow: 0px 0px 4px #999; padding: 2px; display: block; border-radius: 2px; text-decoration: none;" href="http://acordocoletivo.org/2013/03/17/free-web-services/" target="_blank"><img style="padding: 0; margin: 0; border: 0; display: block; width: 80px; max-width: 100%;" alt="" src="http://i2.wp.com/latest-tutorial.com/wp-content/uploads/2013/03/153089259_80_80.jpg" data-recalc-dims="1" /></a><a style="display: block; overflow: hidden; text-decoration: none; line-height: 12pt; height: 80px; padding: 5px 2px 0 2px;" href="http://acordocoletivo.org/2013/03/17/free-web-services/" target="_blank">Free Web Services</a></li>
<li class="zemanta-article-ul-li-image zemanta-article-ul-li" style="padding: 0; background: none; list-style: none; display: block; float: left; vertical-align: top; text-align: left; width: 84px; font-size: 11px; margin: 2px 10px 10px 2px;"><a style="box-shadow: 0px 0px 4px #999; padding: 2px; display: block; border-radius: 2px; text-decoration: none;" href="http://reviews.cnet.com/8301-3514_7-57559328/chrome-search-refinements-on-their-way/?part=rss&amp;subj=news" target="_blank"><img style="padding: 0; margin: 0; border: 0; display: block; width: 80px; max-width: 100%;" alt="" src="http://i2.wp.com/latest-tutorial.com/wp-content/uploads/2013/03/132459599_80_80.jpg" data-recalc-dims="1" /></a><a style="display: block; overflow: hidden; text-decoration: none; line-height: 12pt; height: 80px; padding: 5px 2px 0 2px;" href="http://reviews.cnet.com/8301-3514_7-57559328/chrome-search-refinements-on-their-way/?part=rss&amp;subj=news" target="_blank">Chrome search refinements on their way</a></li>
<li class="zemanta-article-ul-li-image zemanta-article-ul-li" style="padding: 0; background: none; list-style: none; display: block; float: left; vertical-align: top; text-align: left; width: 84px; font-size: 11px; margin: 2px 10px 10px 2px;"><a style="box-shadow: 0px 0px 4px #999; padding: 2px; display: block; border-radius: 2px; text-decoration: none;" href="http://www.slashgear.com/google-animated-gif-search-filter-heres-where-you-find-it-20274764/" target="_blank"><img style="padding: 0; margin: 0; border: 0; display: block; width: 80px; max-width: 100%;" alt="" src="http://i2.wp.com/latest-tutorial.com/wp-content/uploads/2013/03/153746522_80_80.jpg" data-recalc-dims="1" /></a><a style="display: block; overflow: hidden; text-decoration: none; line-height: 12pt; height: 80px; padding: 5px 2px 0 2px;" href="http://www.slashgear.com/google-animated-gif-search-filter-heres-where-you-find-it-20274764/" target="_blank">Google Animated Gif Search Filter: here&#8217;s where you find it</a></li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/?px"><img class="zemanta-pixie-img" style="border: none; float: right;" alt="Enhanced by Zemanta" src="http://i0.wp.com/img.zemanta.com/zemified_e.png" data-recalc-dims="1" /></a></div>
</div>]]></content:encoded>
			<wfw:commentRss>http://latest-tutorial.com/2013/03/22/create-your-own-search-engineinterface-using-google-custom-search-api-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find Out Your Visitor’s Position Using HTML5 Geolocation</title>
		<link>http://latest-tutorial.com/2012/03/15/find-out-your-visitors-position-using-html5-geolocation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-out-your-visitors-position-using-html5-geolocation</link>
		<comments>http://latest-tutorial.com/2012/03/15/find-out-your-visitors-position-using-html5-geolocation/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 07:33:40 +0000</pubDate>
		<dc:creator>Zeeshan Akhter</dc:creator>
				<category><![CDATA[Android Tutorials]]></category>
		<category><![CDATA[Aspx.NET Tutorials]]></category>
		<category><![CDATA[Courses]]></category>
		<category><![CDATA[Java Posts]]></category>
		<category><![CDATA[JavaScript Tutorials]]></category>
		<category><![CDATA[Random Posts]]></category>
		<category><![CDATA[beginner java tutorial]]></category>
		<category><![CDATA[Exception handling]]></category>
		<category><![CDATA[free java tutorials]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[java beginner]]></category>
		<category><![CDATA[java development.]]></category>
		<category><![CDATA[java online tutorial]]></category>
		<category><![CDATA[java programming]]></category>
		<category><![CDATA[java source code]]></category>
		<category><![CDATA[java tutorial]]></category>
		<category><![CDATA[java tutorial video]]></category>
		<category><![CDATA[latitude]]></category>
		<category><![CDATA[learn java]]></category>
		<category><![CDATA[online java tutorial]]></category>
		<category><![CDATA[programmer]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[usage share of web browsers]]></category>
		<category><![CDATA[web browser]]></category>

		<guid isPermaLink="false">http://shanisk.wordpress.com/?p=905</guid>
		<description><![CDATA[Geolocation is a way for the user to retrieve their position and share where they are. This can be done in a few ways, by using a GPS as the one in your new smartphone or connected to your computer is the most precise method. But for users without GPS the browser will use your [...]]]></description>
				<content:encoded><![CDATA[<div class="page-restrict-output"><p>Geolocation is a way for the user to retrieve their position and share where they are. This can be done in a few ways, by using a GPS as the one in your new smartphone or connected to your computer is the most precise method. But for users without GPS the browser will use your IP and or try to find nearby WLAN stations, however this is not as precise but gives some idea of where they are. Exactly how this is done is not a W3C standard and each browser have their own way to do it.</p>
<p>Even though geolocation is really complicated it’s quite easy for you to implement. In this tutorial I will show you how to retrieve the user’s position and display it on a map using Google Maps. So lets get started.</p>
<h2></h2>
<p>[wp_cart:Find Out Your Visitor’s Position Using HTML5 Geolocation:price:6:end]<br />
<?php echo print_wp_cart_button_for_product(’Find Out Your Visitor’s Position Using HTML5 Geolocation’, 6); ?><br />
Step 1. Create the HTML layout</p>
<p>We start of by creating a simple HTML page containing three div tags. One for the current status, one to display the data retrieved and one for displaying the user’s position on a map.</p>
<div>
<div id="highlighter_18125">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</td>
<td>
<div>
<div><code>&lt;!DOCTYPE html&gt;</code></div>
<div><code>&lt;</code><code>html</code><code>&gt;</code></div>
<div><code>  </code><code>&lt;</code><code>head</code><code>&gt;</code></div>
<div><code>    </code><code>&lt;</code><code>title</code><code>&gt;HTML5 Geolocation&lt;/</code><code>title</code><code>&gt;</code></div>
<div><code>    </code><code>&lt;</code><code>script</code> <code>src</code><code>=</code><code>"<a href="http://maps.googleapis.com/maps/api/js?sensor=false">http://maps.googleapis.com/maps/api/js?sensor=false</a>"</code><code>&gt;&lt;/</code><code>script</code><code>&gt;</code></div>
<div><code>  </code><code>&lt;/</code><code>head</code><code>&gt;</code></div>
<div><code>  </code><code>&lt;</code><code>body</code> <code>onload</code><code>=</code><code>"initialize()"</code><code>&gt;</code></div>
<div><code>    </code><code>&lt;</code><code>div</code> <code>id</code><code>=</code><code>"status"</code><code>&gt;&lt;/</code><code>div</code><code>&gt;</code></div>
<div><code>    </code><code>&lt;</code><code>div</code> <code>id</code><code>=</code><code>"data"</code><code>&gt;&lt;/</code><code>div</code><code>&gt;</code></div>
<div><code>    </code><code>&lt;</code><code>div</code> <code>id</code><code>=</code><code>"map_canvas"</code> <code>style</code><code>=</code><code>"width: 640px; height: 480px"</code><code>&gt;&lt;/</code><code>div</code><code>&gt;</code></div>
<div><code>  </code><code>&lt;/</code><code>body</code><code>&gt;</code></div>
<div><code>&lt;/</code><code>html</code><code>&gt;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>We also include the Google Maps API, it’s important to set sensors=false in the URL, otherwise Google will try to find out the user’s position for us.</p>
<p>The initialize function we’re calling on load will try to fetch the position for us.</p>
<h2>Step 2. Retrieve the Position</h2>
<p>Next it’s time to create our initialize function which will call the geolocation API to get the position data.</p>
<div>
<div id="highlighter_125080">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
</td>
<td>
<div>
<div><code>// Initialize geolocation</code></div>
<div><code>function</code> <code>initialize() {</code></div>
<div><code>  </code><code>if</code> <code>(navigator.geolocation) {</code></div>
<div><code>    </code><code>document.getElementById(</code><code>'status'</code><code>).innerHTML = </code><code>'Checking...'</code><code>;</code></div>
<div></div>
<div><code>    </code><code>navigator.geolocation.getCurrentPosition(</code></div>
<div><code>      </code><code>onSuccess,</code></div>
<div><code>      </code><code>onError, {</code></div>
<div><code>        </code><code>enableHighAccuracy: </code><code>true</code><code>,</code></div>
<div><code>        </code><code>timeout: 20000,</code></div>
<div><code>        </code><code>maximumAge: 120000</code></div>
<div><code>      </code><code>});</code></div>
<div><code>  </code><code>}</code></div>
<div><code>  </code><code>else</code> <code>{</code></div>
<div><code>    </code><code>document.getElementById(</code><code>'status'</code><code>).innerHTML = </code><code>'Geolocation not supported.'</code><code>;</code></div>
<div><code>  </code><code>}</code></div>
<div><code>}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>First we check if the browser actually supports geolocation. Browser who supports geolocation are Internet Explorer 9, Firefox 3.5+, Chrome 5+, Opera 10.6+ and Safari 5+. So it’s quite widely supported already, but if the user has an old browser we show them a message telling them that geolocation is not supported.</p>
<p>Next we set the status message to “Checking…” to tell the user that we’re trying to fetch the location data since this might take some time. Then we call navigator.geolocation.getCurrentPosition which will try to retrieve the user’s position, it calls the onSuccess function if it succeeds, otherwise it will call the onError. These functions will be created in the next two steps.</p>
<p>There’s also a few optional parameters to the getCurrentPosition function. These are enableHighAccuracy which tells the web browser to try using the clients GPS if possible, the default value for this is false. The timeout parameter tells the browser how long we’re ready to wait to get the position in milliseconds, the default value is infinite. Lastly we have the maximumAge parameter which tells the browser how old the position cache is allowed to be in milliseconds, the default value for maximumAge is 0 which turns off cache completely.</p>
<p>Since geolocation is a big privacy concern the W3C standards requires the user to agree to share their position before the location is sent to the website, so when we call the getCurrentPosition a information bar will be shown to the user where the user has to allow us to get the position, if the user denies the onError will be function will be called.</p>
<div>
<h3>Tip</h3>
<p>Don’t rely fully on getting the user’s location since the user might deny your site from retrieving the position or something might go wrong. Always have a fallback solution if retrieving the position is critical.</p>
</div>
<h2>Step 3. On Success</h2>
<p>Next we add an onSuccess function to our script section. This function will display the data received and call the loadMap function to load our map.</p>
<div>
<div id="highlighter_779379">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
</td>
<td>
<div>
<div><code>// Map position retrieved successfully</code></div>
<div><code>function</code> <code>onSuccess(position) {</code></div>
<div><code>  </code><code>var</code> <code>data = </code><code>''</code><code>;</code></div>
<div></div>
<div><code>  </code><code>data += </code><code>'latitude: '</code> <code>+ position.coords.latitude + </code><code>'&lt;br/&gt;'</code><code>;</code></div>
<div><code>  </code><code>data += </code><code>'longitude: '</code> <code>+ position.coords.longitude + </code><code>'&lt;br/&gt;'</code><code>;</code></div>
<div><code>  </code><code>data += </code><code>'altitude: '</code> <code>+ position.coords.altitude + </code><code>'&lt;br/&gt;'</code><code>;</code></div>
<div><code>  </code><code>data += </code><code>'accuracy: '</code> <code>+ position.coords.accuracy + </code><code>'&lt;br/&gt;'</code><code>;</code></div>
<div><code>  </code><code>data += </code><code>'altitudeAccuracy: '</code> <code>+ position.coords.altitudeAccuracy + </code><code>'&lt;br/&gt;'</code><code>;</code></div>
<div><code>  </code><code>data += </code><code>'heading: '</code> <code>+ position.coords.heading + </code><code>'&lt;br/&gt;'</code><code>;</code></div>
<div><code>  </code><code>data += </code><code>'speed: '</code> <code>+ position.coords.speed + </code><code>'&lt;br/&gt;'</code><code>;</code></div>
<div></div>
<div><code>  </code><code>document.getElementById(</code><code>'data'</code><code>).innerHTML = data;</code></div>
<div></div>
<div><code>  </code><code>loadMap(position.coords.latitude, position.coords.longitude);</code></div>
<div><code>}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>This function is quite self explanatory, we build a string with the retrieved data found in the position variable and shows it to our user. You will always get the latitude, longitude and accuracy values but the rest is optional and will probably only be set if the user has a GPS which the data is retrieved from.</p>
<p>Lastly we call the loadMap function and give the latitude and longitude to show where the user is on a map.</p>
<h2>Step 4. On Error</h2>
<p>Since geolocation is quite complex a lot can go wrong and we need an error handler. There’s four different error codes, 0 is an unknown error, 1 occurs if you deny the browser from retrieving your location, 2 occurs if the browse somehow fails to retrieve the location and 3 if our timeout variable is too short and the timeout expired.</p>
<div>
<div id="highlighter_19730">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
<div>21</div>
</td>
<td>
<div>
<div><code>// Error handler</code></div>
<div><code>function</code> <code>onError(err) {</code></div>
<div><code>  </code><code>var</code> <code>message;</code></div>
<div></div>
<div><code>  </code><code>switch</code> <code>(err.code) {</code></div>
<div><code>    </code><code>case</code> <code>0:</code></div>
<div><code>      </code><code>message = </code><code>'Unknown error: '</code> <code>+ err.message;</code></div>
<div><code>      </code><code>break</code><code>;</code></div>
<div><code>    </code><code>case</code> <code>1:</code></div>
<div><code>      </code><code>message = </code><code>'You denied permission to retrieve a position.'</code><code>;</code></div>
<div><code>      </code><code>break</code><code>;</code></div>
<div><code>    </code><code>case</code> <code>2:</code></div>
<div><code>      </code><code>message = </code><code>'The browser was unable to determine a position: '</code> <code>+ error.message;</code></div>
<div><code>      </code><code>break</code><code>;</code></div>
<div><code>    </code><code>case</code> <code>3:</code></div>
<div><code>      </code><code>message = </code><code>'The browser timed out before retrieving the position.'</code><code>;</code></div>
<div><code>      </code><code>break</code><code>;</code></div>
<div><code>  </code><code>}</code></div>
<div></div>
<div><code>  </code><code>document.getElementById(</code><code>'status'</code><code>).innerHTML = message;</code></div>
<div><code>}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>This function is also quite easy to understand, we get the error as a parameter to our function and shows the user a message depending on the error code retrieved.</p>
<h3>Step 5. Display the Map</h3>
<p>Next we display a map in our map_canvas div. This has really nothing to do with the HTML5 geolocation. So I won’t explain this for you, but it shouldn’t be too hard to understand.</p>
<div>
<h3>Tip</h3>
<p>If you want to learn more about Google maps check out their API <a href="http://code.google.com/apis/maps/documentation/javascript/" target="_blank">here</a>.</p>
</div>
<div>
<div id="highlighter_136316">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
</td>
<td>
<div>
<div><code>// Integration with google maps</code></div>
<div><code>function</code> <code>loadMap(lat, lng) {</code></div>
<div><code>  </code><code>var</code> <code>latlng = </code><code>new</code> <code>google.maps.LatLng(lat, lng);</code></div>
<div></div>
<div><code>  </code><code>var</code> <code>settings = {</code></div>
<div><code>    </code><code>zoom: 14,</code></div>
<div><code>    </code><code>center: latlng,</code></div>
<div><code>    </code><code>mapTypeId: google.maps.MapTypeId.ROADMAP</code></div>
<div><code>  </code><code>};</code></div>
<div></div>
<div><code>  </code><code>var</code> <code>map = </code><code>new</code> <code>google.maps.Map(document.getElementById(</code><code>'map_canvas'</code><code>), settings);</code></div>
<div></div>
<div><code>  </code><code>var</code> <code>marker = </code><code>new</code> <code>google.maps.Marker({</code></div>
<div><code>    </code><code>position: latlng,</code></div>
<div><code>    </code><code>map: map,</code></div>
<div><code>    </code><code>title: </code><code>'Your Position!'</code></div>
<div><code>  </code><code>});  </code></div>
<div></div>
<div><code>  </code><code>document.getElementById(</code><code>'status'</code><code>).innerHTML = </code><code>'Position Found!'</code><code>;</code></div>
<div><code>}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>That’s all for today. You can try out or download the finished code below.</p>
<div>
<h3>Example</h3>
<p>Try out the finished example here: <a href="http://www.worldwidewhat.net/extras/html5-geolocation/index.htm" target="_blank">Example</a>.</p>
</div>
<div>
<h3>Download</h3>
<p>Download the source from here: <a href="http://www.worldwidewhat.net/extras/html5-geolocation/html5-geolocation.zip">Download</a></p>
</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://latest-tutorial.com/2012/03/15/find-out-your-visitors-position-using-html5-geolocation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
