Skip to content

Instantly share code, notes, and snippets.

View niraj-shah's full-sized avatar
🏠
Working from home

Niraj Shah niraj-shah

🏠
Working from home
View GitHub Profile
<div id="wrapper">
<!-- Page heading -->
<h1>Geolocation</h1>
<!-- Status -->
<p>Finding your location: <span id="status">checking...</span></p>
</div>
<!-- Google Maps JavaScript API -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
@niraj-shah
niraj-shah / geolocation_1.js
Last active December 10, 2015 14:59
Start of JavaScript code for Geolocation Tutorial
function success(position) {
}
function error(msg) {
}
@niraj-shah
niraj-shah / geolocation_2.js
Created January 4, 2013 11:19
JS Code to get Location using Google Maps
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
function success(position) {
}
function error(msg) {
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
function success(position) {
// variable to store the coordinates
var location = position.coords.latitude + ',' + position.coords.longitude;
// select the span with id status
var s = $('#status');
// update the status message
s.html('found you!');
@niraj-shah
niraj-shah / geolocation_4.js
Last active December 10, 2015 18:28
The success function
function success(position) {
// variable to store the coordinates
var location = position.coords.latitude + ',' + position.coords.longitude;
// select the span with id status
var s = $('#status');
// update the status message
s.html('found you!');
// variable to store the coordinates
var location = position.coords.latitude + ',' + position.coords.longitude;
// variable to store the coordinates
var location = position.coords.latitude + ',' + position.coords.longitude;
// select the span with id status
var s = $('#status');
// update the status message
s.html('found you!');
$('#wrapper').append('<img src="http://maps.google.com/maps/api/staticmap?center='+ location +
'&zoom=17&markers=size:medium|color:red|'+ location +
'&path=color:0x0000FF80|weight:2|'+ location +
'&size=480x360&sensor=false" />');