From e80ab9057b287022db2aa6401367d0ab3a8efb34 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 4 Jan 2013 17:13:14 -0500 Subject: [PATCH] Adds geolocation for #157 --- css/app.css | 4 ++++ js/id/id.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/css/app.css b/css/app.css index 9955a37ed..c960d5ddb 100644 --- a/css/app.css +++ b/css/app.css @@ -657,6 +657,10 @@ button.Browse .label { margin: 4px; } +.geolocate-control { + top:260px; +} + /* Map ------------------------------------------------------- */ diff --git a/js/id/id.js b/js/id/id.js index 48c7f307d..3aa6802f3 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -190,6 +190,21 @@ window.iD = function(container) { return d[0] + ' icon'; }); + function geolocateSuccess(position) { + map.center([position.coords.longitude, position.coords.latitude]); + } + function geolocateError() { } + if (navigator.geolocation) { + container.append('div') + .attr('class', 'geolocate-control map-control') + .append('button') + .attr('class', 'narrow') + .text('G') + .on('click', function() { + navigator.geolocation.getCurrentPosition(geolocateSuccess, geolocateError); + }); + } + var gc = container.append('div').attr('class', 'geocode-control map-control') .call(iD.geocoder().map(map));