Skip to content

Instantly share code, notes, and snippets.

@vschmidt94
vschmidt94 / GeometryUtil.js_Closest_snippet
Created November 14, 2014 19:05
Using GeometryUtil.js to compute distances between markers on a Leaflet map
// while we're at it, find the closest marker to user
closest = L.GeometryUtil.closest(map3, points, myLL);
for (i = 0; i < points.length; i++) {
var delta = 1E-14;
var latDiff = Math.abs(points[i].lat - closest.lat);
var lngDiff = Math.abs(points[i].lng - closest.lng);
if (((latDiff < delta) && (lngDiff < delta))) {
closestIdx = i;
closestDist = myLL.distanceTo(points[i]);
@vschmidt94
vschmidt94 / getLoc.js
Created November 14, 2014 19:09
geolocate user, add user to leaflet.js map using custom icon, calculate nearest marker to user
var myMarker = null;
var myLL;
var lat = 0;
var lng = 0;
var closeet = null;
var closestIdx = null;
var closestDist = 0;
// from: http://www.w3schools.com/html/html5_geolocation.asp
@vschmidt94
vschmidt94 / bldgcrawler.php
Created November 14, 2014 19:59
Simple PHP web scraper
<?php
// bldgcrawler.php
// Loops through sequential get requests to the OSU Campus Map and retrieves
// any additional landmark info as JSON reply. Parse JSON reply and output
// to browser.
// Vaughan Schmidt
// schmicar@onid.engr.oregonstate.edu
// 2014.11.13
@vschmidt94
vschmidt94 / leaflet_map_div.html
Created November 14, 2014 20:08
Providing a HTML div for a leaflet.js map
<div id="map1"></div>
<script src="./js/tutMap1.js"></script>
@vschmidt94
vschmidt94 / tutMap1.js
Created November 14, 2014 20:30
JS File to add Leaflet Map to HTML div
var map1 = L.map('map1').setView([44.55957, -123.28141355887], 13);
L.tileLayer('http://{s}.tiles.mapbox.com/v3/YOUR_MAP_ID_HERE/{z}/{x}/{y}.png',
{
attribution: 'Map data &copy; <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>',
maxZoom: 18
}).addTo(map1);
@vschmidt94
vschmidt94 / tutMap2.js
Created November 14, 2014 20:42
Adding a collection of markers to Leaflet.js map & binding popups
var map2 = L.map('map2').setView([44.56357, -123.28141355887], 14);
L.tileLayer('http://{s}.tiles.mapbox.com/v3/YOUR_MAP_ID_HERE/{z}/{x}/{y}.png',
{
attribution: 'Map data &copy; <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>',
maxZoom: 18
}).addTo(map2);
var points = [
{
@vschmidt94
vschmidt94 / RM Example Gist
Created November 16, 2014 01:25
Just an example for R.M.
function playSomeSound(genre) {
SC.get('/tracks', {
genres: genre
//bpm: {
//from: 100
// }
}, function(tracks) {
var random = Math.floor(Math.random() * 49);
SC.oEmbed(tracks[random].uri, { auto_play: true}, document.getElementById('target'));
});
@vschmidt94
vschmidt94 / api.php
Created May 17, 2015 16:58
Publish MySQL table(s) as JSON using PHP webservice
<?php
# Exposes public API to retrieve select data from the Corvallis
# Recycles database.
#
# useage: HTTP GET call to <yoururl>?cmp=1&cat=1&itm=1
#
# note 1: You can request only specific tables if you desire,
# simply set the table flag to 0 if not desired.
#
@vschmidt94
vschmidt94 / build.gradle
Created May 17, 2015 17:50
Dependencies section for HowTo
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile files('libs/android-async-http-1.4.7.jar')
compile files('libs/gson-2.3.1.jar')
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile files('libs/android-async-http-1.4.7.jar')
}