Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get location and display on map

  • Loading branch information...
commit c638bb2872a7aa876433f523162738f38fd5b44f 1 parent d0b37f0
@fmr fmr authored
Showing with 53 additions and 8 deletions.
  1. +50 −6 stores/static/js/stores.js
  2. +3 −2 stores/templates/stores/index.html
View
56 stores/static/js/stores.js
@@ -1,7 +1,49 @@
var stores = stores || {};
stores.maps = {
+
+ overview: {
+ init: function() {
+ var map = stores.maps.createOverviewMap();
+
+ // callback function for when coordinates are found
+ var success = function(position) {
+ var currentLocation = new google.maps.LatLng(
+ position.coords.latitude,
+ position.coords.longitude
+ );
+ var bounds = map.getBounds();
+ bounds.extend(currentLocation);
+ map.fitBounds(bounds);
+
+ var marker = new google.maps.Marker({
+ position: currentLocation,
+ map: map,
+ title: 'You are here'
+ });
+ };
+
+ // callback function for when location could not be determined
+ var error = function(msg) {
+ oscar.messages.error(msg);
+ };
+
+ $('[data-behaviours~=geo-location]').live('click', function(ev) {
+ ev.preventDefault();
+
+ // get location from browser
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(success, error);
+ } else {
+ error('Your location could not be determined');
+ }
+ });
+
+ }
+ },
+
createOverviewMap: function () {
+ var map = null;
$('.store-map').each(function (elem) {
var myOptions = {
center: new google.maps.LatLng(-37.813988, 144.964256),
@@ -11,20 +53,20 @@ stores.maps = {
scrollwheel: true,
zoom: 11
};
- var map = new google.maps.Map(this, myOptions);
+ map = new google.maps.Map(this, myOptions);
var bounds = new google.maps.LatLngBounds();
$('address').each(function (elem) {
var storeLocation = new google.maps.LatLng(
- $(this).attr('data-lat'),
- $(this).attr('data-lng')
+ $(this).data('lat'),
+ $(this).data('lng')
);
bounds.extend(storeLocation);
var marker = new google.maps.Marker({
position: storeLocation,
map: map,
- title: $(this).attr('data-name')
+ title: $(this).data('name')
});
map.fitBounds(bounds);
@@ -39,10 +81,12 @@ stores.maps = {
});
});
+ return map;
},
+
createIndividualMap: function (mapElem, addressElem, zoomLevel) {
- lat = addressElem.attr('data-lat');
- lng = addressElem.attr('data-lng');
+ lat = addressElem.data('lat');
+ lng = addressElem.data('lng');
if (lat & lng) {
storeLocation = new google.maps.LatLng(lat, lng);
View
5 stores/templates/stores/index.html
@@ -12,7 +12,7 @@
<div class="container-fluid page">
<div class="row-fluid">
<div class="span3">
- <a href="@" class="btn btn-primary">Use my location</a>
+ <button class="btn btn-primary" data-behaviours="geo-location">Use my location</button>
       <ul>
           <li>something</li>
           <li>something</li>
@@ -68,6 +68,7 @@ <h1 class="hidden-phone">{% trans "View our stores" %}</h1>
</div>
</div>
</div>
+
{% endblock %}
{% block extrascripts %}
@@ -76,5 +77,5 @@ <h1 class="hidden-phone">{% trans "View our stores" %}</h1>
{% endblock %}
{% block onbodyload %}
- stores.maps.createOverviewMap();
+stores.maps.overview.init();
{% endblock %}

0 comments on commit c638bb2

Please sign in to comment.
Something went wrong with that request. Please try again.