I added the javascript needed to load the google maps into my page:
<% content_for :head do %>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(<%=@lat%>, <%=@lon%>),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
}
</script>
<% end %>
as you can see i need to pass the parameters latitude and longitude when i load the map.
As i said in the title i want to put these javascripts into the asset pipeline, is it possible if yes how ? thanks
You should not include the Google Maps API in your asset-pipeline-generated
application.jsfile. Instead it should be included as a separate<script>tag before yourapplication.js‘s<script>tag.You can then add your
initialize()method into any file included in your asset pipeline, includingapplication.jsitself.You’ll probably want to make
@latand@lonarguments of yourinitializemethod though so they can be defined within your pages<head>. For example, you might haveand in your
application.jsfile you might have