Skip to content

Commit e6beb01

Browse files
author
Juan Pablo Scaletti
committed
Merge branch 'master' of git://github.com/HPNeo/gmaps
2 parents 9d45634 + aaef12f commit e6beb01

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Visit the examples in [hpneo.github.com/gmaps](http://hpneo.github.com/gmaps/)
88
Changelog
99
---------
1010

11+
0.1.8.10
12+
-----------------------
13+
* Better GMaps.Route methods
14+
1115
0.1.8.9
1216
-----------------------
1317
* Fix typo in Polyline events

examples/examples.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ body{
1111
-webkit-box-shadow: 0px 5px 20px #ccc;
1212
box-shadow: 0px 5px 20px #ccc;
1313
}
14+
#map.large{
15+
height:500px;
16+
}
1417

1518
.overlay{
1619
display:block;

examples/travel_route.html

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@
3333
$('#forward').click(function(e){
3434
e.preventDefault();
3535
route.forward();
36+
37+
if(route.step_count < route.steps_length)
38+
$('#steps').append('<li>'+route.steps[route.step_count].instructions+'</li>');
3639
});
3740
$('#back').click(function(e){
3841
e.preventDefault();
3942
route.back();
43+
44+
if(route.step_count >= 0)
45+
$('#steps').find('li').last().remove();
4046
});
4147
});
4248
map = new GMaps({
@@ -58,12 +64,18 @@
5864
<h1>GMaps.js &mdash; Travel route</h1>
5965
<div class="row">
6066
<div class="span16">
61-
<div id="map"></div>
67+
<div id="map" class="large"></div>
6268
</div>
6369
<div class="span5">
64-
<a href="#" class="btn" id="get_route">Get route</a>
65-
<a href="#" class="btn" id="back">&laquo; Back</a>
66-
<a href="#" class="btn" id="forward">Forward &raquo;</a>
70+
<div class="row">
71+
<a href="#" class="btn" id="get_route">Get route</a>
72+
<a href="#" class="btn" id="back">&laquo; Back</a>
73+
<a href="#" class="btn" id="forward">Forward &raquo;</a>
74+
</div>
75+
<div class="row">
76+
<ul id="steps">
77+
</ul>
78+
</div>
6779
</div>
6880
</div>
6981
</body>

gmaps.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,9 @@ GMaps = function(options){
806806
GMaps.Route = function(options){
807807
this.map = options.map;
808808
this.route = options.route;
809-
this.path = this.route.overview_path;
810-
this.steps = this.path.length;
809+
this.step_count = 0;
810+
this.steps = this.route.legs[0].steps;
811+
this.steps_length = this.steps.length;
811812

812813
this.polyline = this.map.drawPolyline({
813814
path: new google.maps.MVCArray(),
@@ -816,19 +817,20 @@ GMaps.Route = function(options){
816817
strokeWeight: options.strokeWeight
817818
}).getPath();
818819

819-
this.polyline.push(this.route.overview_path[0]);
820-
this.path_length = this.polyline.getLength();
821-
822820
this.back = function(){
823-
if (this.path_length > 0){
824-
this.polyline.pop();
825-
this.path_length--;
821+
if (this.step_count > 0){
822+
this.step_count--;
823+
for(p in this.route.legs[0].steps[this.step_count].path)
824+
this.polyline.pop();
826825
}
827826
};
827+
828828
this.forward = function(){
829-
if (this.path_length < this.steps){
830-
this.polyline.push(this.path[this.path_length]);
831-
this.path_length++;
829+
if (this.step_count < this.steps_length){
830+
for(p in this.route.legs[0].steps[this.step_count].path)
831+
this.polyline.push(this.route.legs[0].steps[this.step_count].path[p])
832+
833+
this.step_count++;
832834
}
833835
};
834836
};

0 commit comments

Comments
 (0)