Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:10:45+00:00 2026-06-17T06:10:45+00:00

I am trying to display Google Maps inside a Partial View with JSON. I

  • 0

I am trying to display Google Maps inside a Partial View with JSON. I have already tried the code inside a normal view and it works perfectly fine.

I have the following:-

Partial View ShowMap.cshtml

@using Microsoft.Web.Helpers

<script src="~/Scripts/jquery-1.8.3.min.js"></script>
<div class="experienceRestrictedText">
    @Maps.GetGoogleHtml("1, Redmond Way, Redmond, WA", width: "400", height: "400")
</div>

Index.cshtml (where the Partial view is launched)

    $('.modal_link_map').on('click', function (e) {
        $('.modal_part').show();
        var id = $(this).attr('data-id');
        var context = $('#tn_select').load('/Experience/ShowMap?id=' + id, function () {
            initSelect(context);
        });
        e.preventDefault();
        return false;
    });

And the controller Action is as follows:-

        public ActionResult ShowMap()
        {
        _ItemID = Convert.ToInt32(Request.QueryString["id"]);

        viewModel.ExperienceViewModel.Experience =     unitOfWork.ExperienceRepository.GetByID(_ItemID);

        return PartialView(viewModel);
        }

Do I need to include anything else for this map to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:10:47+00:00Added an answer on June 17, 2026 at 6:10 am

    I am not familiar with the @Maps.GetGoogleHtml helper but I am afraid that somehow this helper is including the following script:

    <script src="//maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
    

    Except that this script cannot be loaded asynchronously because it uses document.write() to load the actual API. To make this work you should specify a callback parameter. Here’s how your partial could look like:

    <div class="experienceRestrictedText">
        <script src="//maps.google.com/maps/api/js?sensor=false&callback=initialize" type="text/javascript"></script>
        <script type="text/javascript">
            function initialize() {
                var map = new google.maps.Map(document.getElementById("map"), { zoom: 14, center: new google.maps.LatLng(47.652437, -122.132424), mapTypeId: google.maps.MapTypeId['ROADMAP'] });
                new google.maps.Geocoder().geocode({ address: '1, Redmond Way, Redmond, WA' }, function (response, status) {
                    if (status === google.maps.GeocoderStatus.OK) {
                        var best = response[0].geometry.location;
                        map.panTo(best);
                        new google.maps.Marker({ map: map, position: best });
                    }
                });
            }
        </script>
        <div class="map" id="map" style="width:400px; height:400px;"></div>
    </div>
    

    Notice how a callback parameter is passed to the http://maps.google.com/maps/api/js script and the actual initialization of the maps is done inside this callback.

    Also notice that I have removed the jquery script from the partial. I guess that jQuery is already loaded in your layout because you seem to be using it to attach to a .on() handler.

    As an alternative you could have included the <script src="//maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> in your main view but once you load the partial, the
    @Maps.GetGoogleHtml helper would have included it a second time.

    Personally I am not a big fan of those kind of helpers because they are completely obscuring the underlying calls leaving you without much control and understanding of what’s happening.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With google maps api (utlizing there new Places Library)Im trying to: Display a map
I'm trying to display a Google Map inside a drupal page. The map will
I'm trying to take the android-wheel from http://code.google.com/p/android-wheel/ and make it display horizontally. My
GOOGLE MAPS API V3 is what i'm trying to use. I have all the
I'm trying to transfer Rails-generated json into Google Maps markers on a map, but
Am trying to display a map for a location with google maps in a
I am trying to hide/show Google Maps by switching between display:none; and display:inherit; .
I am trying to use the geocoding service with the google maps to display
I have jQuery mobile working with google maps so that I can display one,
I've been trying to display Google Maps traffic layer in my app, from what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.