I'm trying to use polyline with gmaps4rails 2 and can't figure out what the error is...
when I hardcode my polyline the map is displayed as expected. However, when I get the data from the controller I get a "Uncaught TypeError: number is not a function"
following code with hardcoded polyline works
view
<script>
$('#myModal2').on('shown.bs.modal', function (e) {
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map2'}}, function(){
polyline = [{"lat":49.9574400,"lng":-123.1201800}, {"lat":49.9465300,"lng":-123.0553700},{"lat":49.9598300,"lng":-123.0475400},{"lat":49.9750500,"lng":-123.0427700}];
handler.addPolyline(polyline);
handler.bounds.extend(polyline[0]);
handler.bounds.extend(polyline[ polyline.length - 1]);
handler.fitMapToBounds();
handler.getMap().setZoom(12);
});
});
</script>
but this one doesn't
<script>
$('#myModal2').on('shown.bs.modal', function (e) {
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map2'}}, function(){
polyline = <%=raw @hashroute.to_json %>;
handler.addPolyline(polyline);
handler.bounds.extend(polyline[0]);
handler.bounds.extend(polyline[ polyline.length - 1]);
handler.fitMapToBounds();
handler.getMap().setZoom(12);
});
});
</script>
controller
def show
@hashroute =[]
@list.routes.each do |route|
@hashroute << { :lat => route.from_lat, :long => route.from_long}
@hashroute << { :lat => route.to_lat, :long => route.to_long}
end
respond_to do |format|
format.html {render :show}
format.json { head :ok}
end
end
the @hashroute.to_json is populated properly and the polyline in the console looks the same as hardcoded version
console
code that works
when it doesn't work
any idea?
In order to close this question which remains open without reason, lets put my answering comment here:
You have to follow the right naming, replace
long
withlng