Last active
August 29, 2015 14:01
-
-
Save makenai/74cf1a8937220c70c3a8 to your computer and use it in GitHub Desktop.
Mapping Things
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Leaflet mobile example</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" /> | |
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<style> | |
body { | |
padding: 0; | |
margin: 0; | |
} | |
html, body, #map { | |
height: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
var map = L.map('map'); | |
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', { | |
maxZoom: 18, | |
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' + | |
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + | |
'Imagery © <a href="http://mapbox.com">Mapbox</a>', | |
id: 'rzrzr.i6clnoj0' | |
}).addTo(map); | |
function onLocationFound(e) { | |
var radius = e.accuracy / 2; | |
L.marker(e.latlng).addTo(map) | |
.bindPopup("You are within " + radius + " meters from this point").openPopup(); | |
L.circle(e.latlng, radius).addTo(map); | |
} | |
function onLocationError(e) { | |
alert(e.message); | |
} | |
map.on('locationfound', onLocationFound); | |
map.on('locationerror', onLocationError); | |
// map.locate({setView: true, maxZoom: 16}); | |
// Geotagging Code | |
var flickrSet = '72157625836754972', | |
apiKey = '6240841f19c9a6efe0905cd6d18daa6f', | |
photosUrl = 'https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=' + apiKey + '&photoset_id=' + flickrSet +'&extras=geo,url_t&format=json'; | |
$( document ).ready(function() { | |
$.getJSON( photosUrl + '&jsoncallback=?', function(data) { | |
// console.log( data ); | |
var viewSet = false; | |
$.each(data.photoset.photo, function(i,photo) { | |
if ( photo.latitude == 0 ) | |
return; | |
var latLng = new L.latLng( photo.latitude, photo.longitude ), | |
icon = new L.icon({ iconUrl: photo.url_t }), | |
marker = L.marker( latLng, { icon: icon } ); | |
marker.addTo( map ); | |
if ( !viewSet ) { | |
// Focus on the first photo | |
map.setView( latLng, 10 ); | |
} | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment