Hi,
I am building a test rails/kendo mobile application which have three main models: Organizations, Shops and Categories.
The shop model has latitude and longitude among its attributes. This is because I would like to show a map on the Shop details view with a marker where the shop is. The first time I view a random shop, the code works fine, and the map renders with the marker. But when I click the back button (browser back button) or the Shops link (in tabstrip) then try to navigate to another shop the map won't show up only if I hit refresh on the browser.
First I thought that this happens because of the changing coordinates (which are placed directly inside the javascript like this: .LatLng(<%=@shop.latitude%>, <%=@shop.longitude%>) ). But no. Even with a simple map like this it won't show up from the second shop view:
function shopMap(e) {
var myOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapElement = $("#shopmap");
var container = e.view.content;
var map = new google.maps.Map(mapElement[0], myOptions);
}
I tried to place the above code directly inside the the view where the shop data is rendered, which would be my preferred way of doing this to be able to change the coordinates dynamically from db, but also tried to place the code in application.html.erb, but no effect (to mimic the google maps example in the code library).
I tried to init the map with the following data attributes:
data-init
data-before-show
data-show
Also tried to set:
data-reload="true"
but none of them and none of their combinations seems to work.
Here is the code for the shop view:
<div data-role="view" data-layout="default" data-show="shopMap" data-reload="true" data-init="shopMap" data-after-show="shopMap" data-title="<%= @shop.title %>" data-zoom="true">
<h1 id="shoptitle"><%= @shop.title %></h1>
<%= image_tag(@shop.logo.thumb.url) %>
<p><%= @shop.description.html_safe %></p>
<p id="latitude"><%= @shop.latitude %></p>
<p id="longitude"><%= @shop.longitude %></p>
<div id="shopmap">
</div>
<script>
function shopMap() {
var myOptions = {
center: new google.maps.LatLng(<%= @shop.latitude %>, <%= @shop.longitude %>),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapElement = $("#shopmap");
var container = e.view.content;
var map = new google.maps.Map(mapElement[0], myOptions);
}
</script>
</div>
The reason why I gave ids to the p tags which contain the latitude and longitude is that I tried to place their values inside js variables to pass them to the shopMap function. But that doesn't work either.
I also tried the kendoMap plugin. But it doesn't work either with the basic settings.
My end goal is to make the map appear without page refresh with the marker which belongs to the currently viewed shop.
Please give me some suggestions, pointers to make this happen!
Best Wishes,
Matt
I am building a test rails/kendo mobile application which have three main models: Organizations, Shops and Categories.
The shop model has latitude and longitude among its attributes. This is because I would like to show a map on the Shop details view with a marker where the shop is. The first time I view a random shop, the code works fine, and the map renders with the marker. But when I click the back button (browser back button) or the Shops link (in tabstrip) then try to navigate to another shop the map won't show up only if I hit refresh on the browser.
First I thought that this happens because of the changing coordinates (which are placed directly inside the javascript like this: .LatLng(<%=@shop.latitude%>, <%=@shop.longitude%>) ). But no. Even with a simple map like this it won't show up from the second shop view:
function shopMap(e) {
var myOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapElement = $("#shopmap");
var container = e.view.content;
var map = new google.maps.Map(mapElement[0], myOptions);
}
I tried to place the above code directly inside the the view where the shop data is rendered, which would be my preferred way of doing this to be able to change the coordinates dynamically from db, but also tried to place the code in application.html.erb, but no effect (to mimic the google maps example in the code library).
I tried to init the map with the following data attributes:
data-init
data-before-show
data-show
Also tried to set:
data-reload="true"
but none of them and none of their combinations seems to work.
Here is the code for the shop view:
<div data-role="view" data-layout="default" data-show="shopMap" data-reload="true" data-init="shopMap" data-after-show="shopMap" data-title="<%= @shop.title %>" data-zoom="true">
<h1 id="shoptitle"><%= @shop.title %></h1>
<%= image_tag(@shop.logo.thumb.url) %>
<p><%= @shop.description.html_safe %></p>
<p id="latitude"><%= @shop.latitude %></p>
<p id="longitude"><%= @shop.longitude %></p>
<div id="shopmap">
</div>
<script>
function shopMap() {
var myOptions = {
center: new google.maps.LatLng(<%= @shop.latitude %>, <%= @shop.longitude %>),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapElement = $("#shopmap");
var container = e.view.content;
var map = new google.maps.Map(mapElement[0], myOptions);
}
</script>
</div>
The reason why I gave ids to the p tags which contain the latitude and longitude is that I tried to place their values inside js variables to pass them to the shopMap function. But that doesn't work either.
I also tried the kendoMap plugin. But it doesn't work either with the basic settings.
My end goal is to make the map appear without page refresh with the marker which belongs to the currently viewed shop.
Please give me some suggestions, pointers to make this happen!
Best Wishes,
Matt