Map.js causes runtime errors...

Apr 23, 2009 at 6:10 PM
Edited Apr 23, 2009 at 6:18 PM

When I build the NerdDinner sample project I get this error:

Microsoft JScript runtime error: Object expected

This happens on the "LoadMap" function call in the map.ascx (and Index.aspx).  I suspected that it wasn't finding the Map.js file, so I put a small test function in there and call that when the page first loads.  Same error.  So for some reason the system can't find the Map.js file.  I've tried moving it to the root of the site, and I've played around with the path in the script tag that loads it, but no matter what I try I just get the same error.  I'm wondering if it's being caused by the routing of MVC?  Does anyone have any idea?

Here's the code I have on that Map.ascx:  

 

 

<script type="text/javascript">
    $(document).ready(
function() {
        var latitude = <%=Model.MeetingLocation.Latitude %>;
        var longitude = <%=Model.MeetingLocation.Longitude %>;

 


 

 

        if ((latitude == 0) || (longitude == 0))
            LoadMap();

 

 

        else  

            LoadMap(latitude, longitude, mapLoaded);

    });

 

    function mapLoaded() {

        var title = "<%= Html.Encode(Model.GroupName) %>";
        
var address = "<%= Html.Encode(Model.MeetingLocation.Address) %>";

 

 

        LoadPin(center, title, address);

        map.SetZoomLevel(14);

    }

 

</

 

script>

And the Map.js file is in the "Scripts" folder in my project - I started with the direct reference to the Map.js file, and someone suggested this method.  Either way I get the same path and the same error... 

Here's the head section of my Site.Master file, for reference:

 

<head runat="server">
    
<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript"></script>
    
<script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>" type="text/javascript"></script>
    
<script src="<%= Url.Content("~/Scripts/jQuery-1.3.2.js") %>" type="text/javascript"></script>

    <
title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    
<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />
</
head>

Thanks for the help!

 

Eddie

Apr 29, 2009 at 11:36 PM
Edited Apr 29, 2009 at 11:38 PM
 Add these to your Map.ascx file.

<
script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" 
    
type="text/javascript"></script>
<
script src="/Scripts/Map.js" type="text/javascript"></script>

 

 

 

 

 

 

 

 

 

 

 

 

Mar 18, 2010 at 4:38 PM

I'm experiencing the same thing.  I think you may be right about the issue being related to the MVC routing.  I'm trying to run through this tutorial in VS 2010 RC and I just can't get the map to show because it can't find the Maps.js.  Anyone else know a solution to this problem?

May 9, 2010 at 11:47 PM
Edited May 10, 2010 at 12:33 AM

Getting the same problem. I'm using VS2010, anybody find a solution?

 

BTW thanks for any replies and hi I'm new!

 

EDIT: Ok so the prob is there was no reference to JQuery  add <script src="/Scripts/jQuery-1.4.1.js" type="text/javascript"></script> to Map.ascx and the map will apear.

The problem I have now is that the map is really bug and occupies the top left corner hiding the content.

Any ideas?

EDIT2: Ok I'm sorting my own stuff here but for other people with this prob its the CSS, havent identified what because I'm too tired and have work in the morn but I switched css with the v2 off nerddinner.com and it works.

 

May 10, 2010 at 4:30 PM
Edited May 10, 2010 at 10:17 PM

I'm using VS2008 express and my Map shows  but i am not getting the pin to show on the map. I have downloaded the latest source code and even went as far as to copy and paste the contents of the NerdDinner.js, Map.ascx and Edit/Create Dinner partial view. But i am still not getting the pin to show. Anyone have any ideas?

EDIT: I got the pin to show on Details. But if i Edit or Create and change the address, the blur doesnt take effect, the map doesnt react at all and i cannot save the Dinner because i get the "Make sure to enter a valid address!" error

May 10, 2010 at 7:20 PM
Hi, When you're on the edit view for a dinner what comes up in the source of the page for the lat long? Should be something like this "$(document).ready( function() { var latitude = 41; var longitude = 20; if ((latitude == 0) || (longitude == 0)) LoadMap(); else LoadMap(latitude, longitude, mapLoaded); });" If its var latitude = ; var longitude = ; It would mean the co-ords arent being pushed to the view.
May 10, 2010 at 10:21 PM
Hey, here is some code from the Map.ascx <script type="text/javascript"> //<![CDATA[ $(document).ready(function() { var latitude = <%= Convert.ToString(Model.Latitude) %>; var longitude = <%= Convert.ToString(Model.Longitude) %>; if ((latitude == 0) || (longitude == 0)) NerdDinner.LoadMap(); else NerdDinner.LoadMap(latitude, longitude, mapLoaded); }); function mapLoaded() { var title = "<%= Html.Encode(Model.Title) %>"; var address = "<%= Html.Encode(Model.Address) %>"; NerdDinner.LoadPin(NerdDinner._map.GetCenter(), title, address); NerdDinner._map.SetZoomLevel(14); } //]]> </script> And heres from the DinnerForm.ascx <script type="text/javascript"> //<![CDATA[ $(document).ready(function() { $("#Address").blur(function(evt) { //If it's time to look for an address, // clear out the Lat and Lon $("#Latitude").val("0"); $("#Longitude").val("0"); var address = jQuery.trim($("#Address").val()); if (address.length < 1) return; NerdDinner.FindAddressOnMap(address); }); }); //]]> </script> I used BeyondCompare to compare my code against the latest Sample and i dont see a difference
May 10, 2010 at 11:32 PM

I'm brand new to ASP.NET and Visual Studio, but I think  the fix requires a change to the Site.Master file.

Change <script src="/Scripts/jQuery-1.3.2.js" type="text/javascript"></script> to <script src="/Scripts/jQuery-1.4.1.js" type="text/javascript"></script>

The  jQuery version is different.  Changing the references fixed the problem for me.

 

May 11, 2010 at 3:50 PM
Edited May 11, 2010 at 8:41 PM

Hey Isaac, the only reading im using that script reference is because i have those files in my Scripts folder. I dont have any jQuery-1.4.1.js files in my project. Also the sample project is also using jQuery-1.3.2. and it works fine...

EDIT I was able to get it to work by removing jQuery-1.3.2.js and jQuery-1.3.2.min-vsdoc.js and adding MSAjaxHistoryBundle.js. Hope no one else has this problem, but if u do, try this after comparing your work with sample.

Coordinator
May 15, 2010 at 12:13 AM

Always make sure you compare your .js files with the version in the trunk using a diff tool. 

Jun 4, 2010 at 4:48 PM
One of the issues with the map is that there are no CSS instructions in the walkthrough. Do a Google search, and you should find something to fix your guys' map problem. After you've added your styling, switching to Firefox should make your view better. My version of IE doesn't work with my CSS, but I hear some of them do. Good luck, and happy coding!
Jun 4, 2010 at 4:49 PM
Hello,

I will be away from the office until Monday, June 14th.


Thanks.

Isaac Alexander
Chief Software Architect
Jun 4, 2010 at 5:21 PM
Edited Jun 4, 2010 at 10:59 PM

OK... my assignment is to learn MVC. My issue (one of them) is the same as the original in this thread. Here's some code to consider:

From Map.ascx:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>
 
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2" type="text/javascript"></script>
<script src="/Scripts/Map.js" type="text/javascript"></script>
<script src="/Scripts/jQuery-1.4.1.js" type="text/javascript"></script>

<div id="theMap">
</div>

<script type="text/javascript">
   
    $(document).ready(function() {
        var latitude = "<%=Model.Latitude%>";
        var longitude = "<%=Model.Longitude%>";
                
        if ((latitude == 0) || (longitude == 0))
            LoadMap();
        else
            LoadMap(latitude, longitude, mapLoaded);
    });
      
   function mapLoaded() {
        var title = "<%=Html.Encode(Model.Title) %>";
        var address = "<%=Html.Encode(Model.Address) %>";
    
        LoadPin(center, title, address);
        map.SetZoomLevel(14);
    } 
      
</script>

From Index.aspx:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>


<asp:Content ID="FindDinnerTitle" ContentPlaceHolderID="TitleContent" runat="server">

    Find a Dinner
    
</asp:Content>


<asp:Content ID="FindDinnerSearch" ContentPlaceHolderID="MainContent" runat="server">

    <script src="/Scripts/Map.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function() {
            LoadMap();
        });

        $("#search").click(function(evt) {
            var where = jQuery.trim($("#Location").val());
            if (where.length < 1) 
                return;

            FindDinnersGivenLocation(where);
        });

    </script>
    
    <div id="mapDivLeft">

        <div id="searchBox">
            Enter your location: <%=Html.TextBox("Location") %>
            <input id="search" type="submit" value="Search"/>
        </div>

        <div id="theMap">
        </div>

    </div>

    <div id="mapDivRight">
        <div id="dinnerList"></div>
    </div>
    
</asp:Content>

 It blows up at the call to "LoadMap():" with the "Microsoft JScript runtime error: Object expected" error. I can get the map to appear on all of the other pages up to this point, but not here. Anybody got a bone to throw me?

Randy

Added comment: I spoke too soon. The map blows on all pages at the "LoadMap(latitude, longitude, mapLoaded);" line under "LoadMap():" What I want to do is make the app work as described in the tutorial, not necessarily download the latest code and try to figure it out from there. This is my third attempt, each time starting from scratch. However I'm almost at the point where I don't itch anymore... (get it?!) oye vey...