diff --git a/examples/geolocation.js b/examples/geolocation.js index e1c3320bad..1afc12d997 100644 --- a/examples/geolocation.js +++ b/examples/geolocation.js @@ -47,6 +47,7 @@ var pulsate = function(feature) { }; var geolocate = new OpenLayers.Control.Geolocate({ + bind: false, geolocationOptions: { enableHighAccuracy: false, maximumAge: 0, @@ -54,7 +55,8 @@ var geolocate = new OpenLayers.Control.Geolocate({ } }); map.addControl(geolocate); -geolocate.events.register("locationupdated",this,function(e) { +var firstGeolocation = true; +geolocate.events.register("locationupdated",geolocate,function(e) { vector.removeAllFeatures(); var circle = new OpenLayers.Feature.Vector( OpenLayers.Geometry.Polygon.createRegularPolygon( @@ -80,8 +82,12 @@ geolocate.events.register("locationupdated",this,function(e) { ), circle ]); - map.zoomToExtent(vector.getDataExtent()); - pulsate(circle); + if (firstGeolocation) { + map.zoomToExtent(vector.getDataExtent()); + pulsate(circle); + firstGeolocation = false; + this.bind = true; + } }); geolocate.events.register("locationfailed",this,function() { OpenLayers.Console.log('Location detection failed'); @@ -92,6 +98,7 @@ $('locate').onclick = function() { geolocate.deactivate(); $('track').checked = false; geolocate.watch = false; + firstGeolocation = true; geolocate.activate(); }; $('track').onclick = function() { @@ -99,6 +106,7 @@ $('track').onclick = function() { geolocate.deactivate(); if (this.checked) { geolocate.watch = true; + firstGeolocation = true; geolocate.activate(); } };