Skip to content

Commit

Permalink
geocoder MVC
Browse files Browse the repository at this point in the history
Signed-off-by: fpumir <[email protected]>
  • Loading branch information
fpumir committed Oct 23, 2014
1 parent 54ee902 commit 4e801a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
14 changes: 12 additions & 2 deletions board/js/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var UI={
mapTypeId: google.maps.MapTypeId.ROADMAP,
center:centered
}
var map=new google.maps.Map(document.querySelector('#map > div'),settings);
callback.call(this,map);
this.map=new google.maps.Map(document.querySelector('#map > div'),settings);
callback.call(this);
},

toggleMap : function(){
Expand All @@ -53,6 +53,16 @@ var UI={
toggleLoader : function(){
document.querySelector('.loader').classList.toggle('on');
return this;
},

setMarker : function(latLng){
new google.maps.Marker({position:latLng,map:this.map});
return this;
},

setCenter : function(latLng){
this.map.panTo(latLng);
return this;
}

}
Expand Down
16 changes: 6 additions & 10 deletions board/js/cards.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";


var card={},mapCanvas;
var card={};

var addCard=document.getElementById('addCard');
addCard.addEventListener('submit',getCard,false);
Expand Down Expand Up @@ -46,8 +46,7 @@ function addLocation(e){
e.preventDefault();
UI.toggleLoader();
model.getUserLocation(function(userPos){
UI.drawMap(userPos,function(map){
mapCanvas=map;
UI.drawMap(userPos,function(){
UI.toggleMap().toggleLoader();
});
});
Expand All @@ -57,14 +56,11 @@ function geoCoder(e){
e.preventDefault();
var address=document.querySelector("input[name='address']").value;
if(!address){return;}
var geocoder = new google.maps.Geocoder();
geocoder.geocode({"address":address},function(data,status){
if(status=='OK'){
var latLng=data[0].geometry.location;
new google.maps.Marker({position:latLng,map:mapCanvas});
mapCanvas.panTo(latLng);
}
model.geocode(address,function(latLng){
UI.setMarker(latLng).setCenter(latLng);
});


}


Expand Down
11 changes: 9 additions & 2 deletions board/js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ var model={
);
},



geocode : function(address,callback){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({"address":address},function(data,status){
if(status=='OK'){
var latLng=data[0].geometry.location;
callback.call(this,latLng);
}
});
}
}


Expand Down

0 comments on commit 4e801a7

Please sign in to comment.