snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#27262

JavaScript

HTML5 Geo Location

1
2
3
4
5
6
navigator.geolocation.getCurrentPosition(function(position) {
    var latitude = position.coords.latitude,
        longitude = position.coords.longitude;

    $('#geoDemo').html('<img src="http://maps.google.com/maps/api/staticmap?center='+latitude+','+longitude +'&zoom=14&size=600x400&maptype=roadmap&sensor=false&markers='+latitude+','+longitude +'" />');
  }, errorHandler);
https://snipt.net/embed/a841ef05955ae5de0107b1f90a1ce00f/
https://snipt.net/raw/a841ef05955ae5de0107b1f90a1ce00f/
a841ef05955ae5de0107b1f90a1ce00f
js
JavaScript
7
2014-04-22T00:37:04
True
False
/api/public/snipt/27262/
html5-geo-location
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nx">navigator</span><span class="p">.</span><span class="nx">geolocation</span><span class="p">.</span><span class="nx">getCurrentPosition</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">position</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">latitude</span> <span class="o">=</span> <span class="nx">position</span><span class="p">.</span><span class="nx">coords</span><span class="p">.</span><span class="nx">latitude</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">longitude</span> <span class="o">=</span> <span class="nx">position</span><span class="p">.</span><span class="nx">coords</span><span class="p">.</span><span class="nx">longitude</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#geoDemo&#39;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="s1">&#39;&lt;img src=&quot;http://maps.google.com/maps/api/staticmap?center=&#39;</span><span class="o">+</span><span class="nx">latitude</span><span class="o">+</span><span class="s1">&#39;,&#39;</span><span class="o">+</span><span class="nx">longitude</span> <span class="o">+</span><span class="s1">&#39;&amp;zoom=14&amp;size=600x400&amp;maptype=roadmap&amp;sensor=false&amp;markers=&#39;</span><span class="o">+</span><span class="nx">latitude</span><span class="o">+</span><span class="s1">&#39;,&#39;</span><span class="o">+</span><span class="nx">longitude</span> <span class="o">+</span><span class="s1">&#39;&quot; /&gt;&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">},</span> <span class="nx">errorHandler</span><span class="p">);</span> </span></pre></div> </td></tr></table>
geolocation, googlemaps, html5, jquery, js