Update Google map through WCF Ajax Service

Posted on 2011-04-18
Last Modified: 2013-11-19

We have scenario in project to update google map through WCF AJAX service.

1. On a aspx page I have checkbox list to filter, search results and based on search result location google map shows locations.

2. When I select checkbox to filter, search result updates and google map should also get updated.

3. Google map is not updating.

Source Code:

On checkbox selection,
var CurrentPage;
function RetrieveDiscounts(currentLocationId, discountDateRanges, pageNumber) {

                                currentLocationId, null, discountDateRanges, discountDateRanges, DiscountItems, VenueTypes, DiscountKeyword, VenueKeyword, MinValue, pageNumber,
                                PageSize, SortOrder, DiscountType, OtherDiscountType, isDisountCard, VenueName, VenueAddress, state, city, venuedistance, 1, onFindDiscountsComplete, onFindDiscountsError)

Ajax service source code:
        public string[] FindValidDiscounts(int locationId, GeoLocation userLocation, DateTime discountStartDate, DateTime discountEndDate, IEnumerable<int> discountItemIds,
                                    IEnumerable<int> venueTypesIds, string discountKeyword, string venueKeyword, double minDiscountValue, int pageNumber, byte pageSize,
                                    DiscountSearchOrder orderBy, IEnumerable<int> DiscountType, IEnumerable<int> DiscountOtherType, int Iscard, string VenueName, string VenueAddess, string State, string City, string venuedistance, Int32 isTrue)

Page pageHolder = new Page();
Map omap = (Map)pageHolder.LoadControl("~/_Parts/utility/Map.ascx");
int VenueCounter = 0;
            foreach (SearchResult oSearchResult in oDiscountSearchResponse.SearchResults)
                VenueCounter += 1;
                omap.AddLocation(oSearchResult.Venue.GeoLocation.Latitude, oSearchResult.Venue.GeoLocation.Longitude, VenueCounter, "");

string[] str = new string[5];

            omap.SetCenter(72.12, 72.19);
            omap.ZoomLevel = 10;

            StringWriter Mapoutput = new StringWriter();
            HttpContext.Current.Server.Execute(pageHolder, Mapoutput, false);
            str[0] = Mapoutput.ToString();

            return str;


When AJAX call completes

//ajax success
function onFindDiscountsComplete(results, context, methodName) {

   document.getElementById('MapContainer').innerHTML = results[0];


MapContainer is div tag on aspx page.
Our problem is that google map is not refreshing on ajax call.

Can any one give great thoughts over it?

Best Regards,
Question by:MohitPandit
    LVL 13

    Expert Comment

    why don't you use Google Maps API toolkit, they have excellent functionalities.
    LVL 5

    Author Comment

    We have architecute like that and we need to follow this only. Do you have your great suggestions?
    LVL 5

    Author Comment

    Yes, I found the answer myselft for this and I will update when I will be in the office.
    LVL 5

    Accepted Solution

    Solution found myself:

    We have to again update the JavaScript reference  and load it using Jquery  or update reference through registering the google map javascript api reference.Following is the code for this problem.

    function loadScript() {

        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "";

    This will update the javascript reference for google map and will update Google map asynchrously
    LVL 5

    Author Closing Comment

    Found solution myself and I hope that it will helpful

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    erros on link  checking 2 24
    HTML table 7 38
    Problem to Popup 37 61
    Summernote required 3 19
    OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now