Google map not showing in partial view

i am working on an mvc3 application.

I am trying to load a google map inside a partial view but it is not working:

My partial view _Map.cshtml

<style type="text/css">  
        height: 450px;

<script type="text/javascript" src=""></script>
<div class="sTitle">Name</div>

<div id="map_canvas"></div>

<script type="text/javascript">
var map;
$(document).ready(function () {
    var map;
    var myOptions = {
        zoom: 8,
        center: new google.maps.LatLng(-34.397, 150.644),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    map = new google.maps.Map(document.getElementById('map_canvas'),

    google.maps.event.addDomListener(window, 'load', initialize);


The map is loaded Via an AJAX Call:

                type: 'GET',
                url: '@Url.Action("GetMapById", "Map")',
                data: { 'id': sId },
                success: function (html) {
                complete: function () {
                error: function () {
                    alert("There was an error opening the Map. Please try again or contact an administrator");

The partial is loaded in a div named Content

And in the controller I just return the Partial View

 return PartialView("_Map");

The View is loading but the map is not visible.

I used Firebug to track the problem and I got this error:

“google is not defined”

Any idea about the problem?

Thanks a lot


I solved this by putting this

<script type="text/javascript" src=""></script>

in the Layout page nad not in the subview

You have to load google map in this way:

<script type="text/javascript">
   var map;
   google.load("maps", "3", { other_params:"sensor=false" });
   $(document).ready(function () {

And you reinitialize "var map" two times.

I didn't want to load the maps in a Layout page... Doing that would mean that if the script was taking long to load, it would slow the whole page and besides, if it is not needed there, then why make the browser download it?

To get around that, I found that you can load the maps API in your partial view like this:

$.getScript('',function (){
  google.maps.event.addDomListener(window, 'load', initialize);

Need Your Help

Can I configure the ResetPassword in Asp.Net's MembershipProvider? passwords reset sqlmembershipprovider

I have an C# app using the default Sql MembershipProvider. My web.config has a few settings that control how I'm using this Provider: