Default MVC project with google map http://forums.asp.net/t/1792859.aspx/1?Default+MVC+project+with+google+map+Mon, 16 Apr 2012 16:33:55 -040017928594932346http://forums.asp.net/p/1792859/4932346.aspx/1?Default+MVC+project+with+google+map+Default MVC project with google map <p>Hi,</p> <p>This code (2 files) works fine itself, but I would like to embed it in MVC default project.</p> <p>How the code can be devided into project pages (Index.chtml, _Layout.cshtml etc.)?&nbsp;</p> <p><strong><span style="text-decoration:underline">index.html</span></strong></p> <p>&lt;!DOCTYPE HTML&gt;<br> &lt;html lang=&quot;en-US&quot;&gt;<br> &lt;head&gt;<br> &lt;meta charset=&quot;UTF-8&quot;&gt;<br> &lt;title&gt;Main Page&lt;/title&gt;<br> &lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css&quot; /&gt;<br> &lt;script src=&quot;http://code.jquery.com/jquery-1.4.3.min.js&quot;&gt;&lt;/script&gt;<br> &lt;script src=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js&quot;&gt;&lt;/script&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br> &lt;div data-role=&quot;page&quot;&gt;<br> &lt;div data-role=&quot;header&quot;&gt;&lt;h1&gt;Main Page&lt;/h1&gt;&lt;/div&gt;<br> &lt;div data-role=&quot;content&quot;&gt;&lt;p&gt;&lt;a href=&quot;map.html&quot;&gt;Map&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;<br> &lt;/div&gt;<br> &lt;script type=&quot;text/javascript&quot; src=&quot;http://maps.google.com/maps/api/js?sensor=false&quot;&gt;&lt;/script&gt;<br> &lt;script type=&quot;text/javascript&quot;&gt;<br> // When map page opens get location and display map<br> &#36;('.page-map').live(&quot;pagecreate&quot;, function() {<br> if(navigator.geolocation) {<br> navigator.geolocation.getCurrentPosition(function(position){<br> initialize(position.coords.latitude,position.coords.longitude);<br> });<br> }<br> });<br> <br> function initialize(lat,lng) {<br> var latlng = new google.maps.LatLng(lat, lng);<br> var myOptions = {<br> zoom: 8,<br> center: latlng,<br> mapTypeId: google.maps.MapTypeId.ROADMAP<br> };<br> var map = new google.maps.Map(document.getElementById(&quot;map_canvas&quot;),myOptions);<br> }<br> &lt;/script&gt;<br> &lt;/body&gt;<br> &lt;/html&gt;</p> <p><span style="text-decoration:underline"><strong>Map.html</strong></span></p> <p>&lt;div data-role=&quot;page&quot; data-theme=&quot;b&quot; class=&quot;page-map&quot; style=&quot;width:100%; height:100%;&quot;&gt;<br> &lt;div data-role=&quot;header&quot;&gt;&lt;h1&gt;Map Page&lt;/h1&gt;&lt;/div&gt;<br> &lt;div data-role=&quot;content&quot; style=&quot;width:100%; height:100%; padding:0;&quot;&gt; <br> &lt;div id=&quot;map_canvas&quot; style=&quot;width:100%; height:100%;&quot;&gt;&lt;/div&gt;<br> &lt;/div&gt;<br> &lt;/div&gt;</p> <p><span style="text-decoration:underline"><strong><br> </strong></span></p> 2012-04-14T11:40:24-04:004932581http://forums.asp.net/p/1792859/4932581.aspx/1?Re+Default+MVC+project+with+google+map+Re: Default MVC project with google map <p>Put the following in your layout file</p> <pre class="prettyprint">&lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css&quot; /&gt; &lt;script src=&quot;http://code.jquery.com/jquery-1.4.3.min.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js&quot;&gt;&lt;/script&gt;</pre> <p>In the home controller index view put the following (notice i changed the link to an action link):</p> <pre class="prettyprint">&lt;div data-role="page"&gt; &lt;div data-role="header"&gt;&lt;h1&gt;Main Page&lt;/h1&gt;&lt;/div&gt; &lt;div data-role="content"&gt; &lt;p&gt; @Html.ActionLink("Map","Map","Home") &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; // When map page opens get location and display map &#36;('.page-map').live("pagecreate", function() { if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position){ initialize(position.coords.latitude,position.coords.longitude); }); } }); function initialize(lat,lng) { var latlng = new google.maps.LatLng(lat, lng); var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions); } &lt;/script&gt;</pre> <p><br> <br> In the home controller create an action named &quot;Map&quot; and build a view for it. In the view put the following:<br> <span>&lt;div data-role=&quot;page&quot; data-theme=&quot;b&quot; class=&quot;page-map&quot; style=&quot;width:100%; height:100%;&quot;&gt;</span><br> <span>&lt;div data-role=&quot;header&quot;&gt;&lt;h1&gt;Map Page&lt;/h1&gt;&lt;/div&gt;</span><br> <span>&lt;div data-role=&quot;content&quot; style=&quot;width:100%; height:100%; padding:0;&quot;&gt;&nbsp;</span><br> <span>&lt;div id=&quot;map_canvas&quot; style=&quot;width:100%; height:100%;&quot;&gt;&lt;/div&gt;</span><br> <span>&lt;/div&gt;</span><br> <span>&lt;/div&gt;</span>&nbsp;</p> 2012-04-14T16:42:54-04:004932631http://forums.asp.net/p/1792859/4932631.aspx/1?Re+Default+MVC+project+with+google+map+Re: Default MVC project with google map <p>hi,</p> <p>Thank you for reply.</p> <p>Unfortunetly, map view remains gray and I can't see the map.</p> <p>&nbsp;I put alert message after: <em>&#36;('.page-map').live(&quot;pagecreate&quot;, function ()&nbsp;</em> but the message is not fired.</p> <p>any idea?</p> 2012-04-14T17:44:28-04:004932667http://forums.asp.net/p/1792859/4932667.aspx/1?Re+Default+MVC+project+with+google+map+Re: Default MVC project with google map <p></p> <blockquote><span class="icon-blockquote"></span> <h4>zionz</h4> I put alert message after: <em>&#36;('.page-map').live(&quot;pagecreate&quot;, function ()&nbsp;</em> but the message is not fired.</blockquote> <p></p> <p>See javascrip errors( enable show errors in IE)</p> <p></p> 2012-04-14T18:58:31-04:004933590http://forums.asp.net/p/1792859/4933590.aspx/1?Re+Default+MVC+project+with+google+map+Re: Default MVC project with google map You can also use IE9's developer tool &gt; network &gt; start to see if your scripts are loading properly. 2012-04-16T02:19:56-04:004933642http://forums.asp.net/p/1792859/4933642.aspx/1?Re+Default+MVC+project+with+google+map+Re: Default MVC project with google map <p>Hi</p> <p>Did you get any error messages? If yes, please post it to us.</p> <p>Regards<br> Young Yang</p> 2012-04-16T04:00:25-04:004935122http://forums.asp.net/p/1792859/4935122.aspx/1?Re+Default+MVC+project+with+google+map+Re: Default MVC project with google map <p>Thank you all.</p> <p>Delete the following lines solved the problem.</p> <p>&nbsp;</p> <pre class="prettyprint">&lt;link href=&quot;@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(&quot;~/Content/css&quot;)&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt; &lt;script src=&quot;@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(&quot;~/Scripts/js&quot;)&quot;&gt;&lt;/script&gt;</pre> <p></p> <p><span face="Consolas" color="#006400" size="2" style="color:#006400; font-family:Consolas; font-size:small"><span face="Consolas" color="#006400" size="2" style="color:#006400; font-family:Consolas; font-size:small"><span face="Consolas" color="#006400" size="2" style="color:#006400; font-family:Consolas; font-size:small"></span></span></span>&nbsp;</p> 2012-04-16T16:33:55-04:00