Google Maps not working

Last post 11-19-2009 9:34 AM by andresossa. 4 replies.

Sort Posts:

  • Google Maps not working

    06-29-2009, 9:57 AM
    • Member
      3 point Member
    • tmargot
    • Member since 03-09-2009, 10:10 PM
    • Posts 21

     Google maps is not working and for the life of me cannot figure out why. It works in a straight HTML file. At first I thought it may be the ASP.NET Menu Control conflicting, but now I have created this basic file and it still does not work. I call the Google Map code from the body onload, but then decided for testing to do it simple as below. Could someone please help?

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="map_no_master.aspx.cs" Inherits="AccountsRapport.map_no_master" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <div id="map_canvas" style="width: 300; height: 300;"></div>
      <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
      <script type="text/javascript">
      	var myLatlng = new google.maps.LatLng(51.372149, -0.457936);
      	var myOptions = {
      		zoom: 15,
      		center: myLatlng,
      		mapTypeId: google.maps.MapTypeId.ROADMAP
      	}
      	var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
    
    
      	var marker = new google.maps.Marker({
      		position: myLatlng,
      		map: map,
      		title: 'Accounts Rapport'
      	});   
    </script>
    
        </div>
        </form>
    </body>
    </html>
    


     

    Filed under:
  • Re: Google Maps not working

    06-30-2009, 2:53 AM

    Hi,

    nothing wrong with the code just put :

    <div id="map_canvas" style="width: 300px; height: 300px;"></div> and the map will come nicely and you can smile.

    Always "Mark as Answer" the Post That Solves the problem.Because It helps others to find the solution.
    Mohammad Hussain
    http://mohdhussain.blogspot.com/
  • Re: Google Maps not working

    06-30-2009, 4:50 AM
    • Member
      3 point Member
    • tmargot
    • Member since 03-09-2009, 10:10 PM
    • Posts 21

    mohd786hussain:

    Hi,

    nothing wrong with the code just put :

    <div id="map_canvas" style="width: 300px; height: 300px;"></div> and the map will come nicely and you can smile.

     

    Thanks very much for the reply. I still have the problem even after placing the div (I had multiple versions for testing and forgot the div on that specific test.

    I found my problem lies in the doctype, if I remove it, everything works fine. I have tried different doctypes but still have the same problem.

  • Re: Google Maps not working

    07-26-2009, 3:47 PM
    Answer
    • Member
      3 point Member
    • tmargot
    • Member since 03-09-2009, 10:10 PM
    • Posts 21

    After looking at many solution on registering google's javascript with ASP.NET I cheated and put the map into a standard HTML file and placed an iFrame on the asp.net page with the map.html file loaded into it.

  • Re: Google Maps not working

    11-19-2009, 9:34 AM
    • Member
      2 point Member
    • andresossa
    • Member since 11-19-2009, 9:25 AM
    • Posts 1

    Hi I have a problem with google maps as well and I have tried everything to solve it. Please help me.

    the maps are loaded perfectly if the page  is the index of a controller. But if the page has parameters on the route or if it isn't the index of the controller, then the map doesn't loads.

    For example,I have the following action for a view.

    public ActionResult Mapa(int id)
            {
                List<Jefe> jefes = repositorio.GetJefesPorEvento(id);
                List<Vendedor> vendedores = new List<Vendedor>();
                if (jefes.Count > 0)
                {
                    vendedores.AddRange(repositorio.GetVendedoresPorEvento(jefes[0]));
                }

                return View("Mapa", vendedores);
            }

    This doesn't work..


    but if I change it to this:

    public ActionResult Index()
            {
                List<Jefe> jefes = repositorio.GetJefesPorEvento(7); //it can be any number of a certain event (party, dinner, etc).
                List<Vendedor> vendedores = new List<Vendedor>();
                if (jefes.Count > 0)
                {
                    vendedores.AddRange(repositorio.GetVendedoresPorEvento(jefes[0]));
                }

                return View("Index", vendedores);
            }

    (the views are exaclty the same of course, so the problem shouldn't be there.)

    then it works.

    Please help me if you can!

    Thanks!

Page 1 of 1 (5 items)