aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/fixmystreet.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/js/fixmystreet.js')
-rw-r--r--web/js/fixmystreet.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js
index 9fa0f948b..48d66360b 100644
--- a/web/js/fixmystreet.js
+++ b/web/js/fixmystreet.js
@@ -83,4 +83,32 @@ $(function(){
}
});
+ // Geolocation
+ if (geo_position_js.init()) {
+ $('#postcodeForm').append('<p id="geolocate_para">Or <a href="#" id="geolocate_link">locate me automatically</a>').css({ "padding-bottom": "0.5em" });
+ $('#geolocate_link').click(function(e) {
+ e.preventDefault();
+ // Spinny thing!
+ $('#geolocate_para').append(' <img src="/i/flower.gif" alt="" align="bottom">');
+ geo_position_js.getCurrentPosition(function(pos) {
+ $('#geolocate_para img').remove();
+ var latitude = pos.coords.latitude;
+ var longitude = pos.coords.longitude;
+ location.href = '/around?latitude=' + latitude + ';longitude=' + longitude;
+ }, function(err) {
+ $('#geolocate_para img').remove();
+ if (err.code == 1) { // User said no
+ } else if (err.code == 2) { // No position
+ $('#geolocate_para').html("Could not look up location");
+ } else if (err.code == 3) { // Too long
+ $('#geolocate_para').html("No result returned");
+ } else { // Unknown
+ $('#geolocate_para').html("Unknown error");
+ }
+ }, {
+ timeout: 10000
+ });
+ });
+ }
+
});