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 6323441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:31:01+00:00 2026-05-24T16:31:01+00:00

You Have edited script according to v2 i am getting this error on using

  • 0

You Have edited script according to v2 i am getting this error on using that script pic attached on line 154

GEvent.addListener(window.polyline, 'click', function() {
                                    window.polyline.setOptions(options: { strokeColor: 'blue' });

You Have edited script according to v2 i am getting this error on using that script pic attached How can we change color of icon and polyline by click on running application? My code is as follows. It has no error. How can I do this?

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace GoogleMap
{
    // A sample project by Ghaffar khan

    public partial class Map : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet1TableAdapters.LocationsTableAdapter da = new GoogleMap.DataSet1TableAdapters.LocationsTableAdapter();
            DataSet1.LocationsDataTable table = new DataSet1.LocationsDataTable();
            da.Fill(table);
            BuildScript(table);
            //GooglePolyline PL1 = new GooglePolyline();

        }
        private void BuildScript(DataTable tbl)
        {
            String Locations = "";
            foreach (DataRow r in tbl.Rows)
            {
                // bypass empty rows        
                if (r["Latitude"].ToString().Trim().Length == 0)
                    continue;

                string Latitude = r["Latitude"].ToString();
                string Longitude = r["Longitude"].ToString();
                // create a line of JavaScript for marker on map for this record    
                Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + Latitude + "," + Longitude + ")));";

            }

            // construct the final script
            js.Text = @"<script type='text/javascript'>
                            function initialize() {
                              if (GBrowserIsCompatible()) {
                                var map = new GMap2(document.getElementById('map_canvas'));
                                map.setCenter(new GLatLng(45.05,7.6667), 2); 
                                map.openInfoWindowHtml ( new GLatLng(45.05,7.6667), 'Serif<br>Pakistan');
                                " + Locations + @"
                                map.setUIToDefault();

// Create an array with points  
var points = [  
   new GLatLng(24.85229, 67.01703),  
   new GLatLng(24.914463, 67.0965958),  
   new GLatLng(24.86588, 67.06089),  
new GLatLng(24.9726753, 67.06638),
new GLatLng(24.840023, 67.24285),
new GLatLng(24.85229, 67.01703)
];  

// Create a new polyline  
var polyline = new GPolyline(points, '#ff0000', 5, 0.7);  

// Add the polyline to the map using map.addOverlay()  
map.addOverlay(polyline);
var marker = new GMarker(new GLatLng(45.05,7.6667))  
// 

                              }
                            }


                            </script> ";
        }       

    }
}

//////The Script According to GergL is,///////

           js.Text = @"<script type='text/javascript'>
                            function initialize() {
                              if (GBrowserIsCompatible()) {
                                window.polyline = new GPolyline(points, '#ff0000', 5, 0.7); 
                                var map = new GMap2(document.getElementById('map_canvas'));
                                map.setCenter(new GLatLng(45.05,7.6667), 2); 
                                map.openInfoWindowHtml ( new GLatLng(45.05,7.6667), 'Serif<br>Pakistan');
                                " + Locations + @"
                                map.setUIToDefault();
google.maps.event.addListener(window.polyline, 'click', function() {
    window.polyline.setOptions(options: { strokeColor: 'blue' });
});
// Create an array with points  
var points = [  
   new GLatLng(24.85229, 67.01703),  
   new GLatLng(24.914463, 67.0965958),  
   new GLatLng(24.86588, 67.06089),  
new GLatLng(24.9726753, 67.06638),
new GLatLng(24.840023, 67.24285),
new GLatLng(24.85229, 67.01703)
];  

// Create a new polyline  
var polyline = new GPolyline(points, '#ff0000', 5, 0.7);  

// Add the polyline to the map using map.addOverlay()  
map.addOverlay(polyline);                          
                              }
                            }
google.maps.event.addListener(window.polyline, 'click', function() {
    window.polyline.setOptions(options: { strokeColor: 'blue' });
});
                            </script> ";

But i am getting error .. .Object Expected in line 47 in script where i use click method in that line hopes for your help !

You Have edited script according to v2 i am getting this error on using that script pic attached

  • 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-05-24T16:31:02+00:00Added an answer on May 24, 2026 at 4:31 pm

    You need to assign your polyline variable in the initialize() function to a globally accessible variable, and then use the setOptions() method on it to set the new colour in your click event handler (in javascript).

    e.g. if you changed the line in initialise() from this:

    var polyline = new GPolyline(points, '#ff0000', 5, 0.7);  
    

    to this:

    window.polyline = new GPolyline(points, '#ff0000', 5, 0.7); 
    

    And then wanted to have it change to blue when clicked, you would add code like:

    GEvent.addListener(window.polyline, 'click', function() {
        window.polyline.setOptions(options: { strokeColor: 'blue' });
    });
    

    I haven’t tested this, btw. But it should help you get on the right track.

    EDIT: Here is what I think your script should be:
    EDIT 2: Updated to work with API v2, though be aware Google strongly encourages you to migrate to the new V3 on both the V2 documentation page and the V3 documentation page.

    js.Text = @"<script type='text/javascript'>
                                function initialize() {
                                  if (GBrowserIsCompatible()) {
                                    var map = new GMap2(document.getElementById('map_canvas'));
                                    map.setCenter(new GLatLng(45.05,7.6667), 2);
                                    map.openInfoWindowHtml ( new GLatLng(45.05,7.6667), 'Serif<br>Pakistan');
                                    " + Locations + @"
                                    map.setUIToDefault();
                                    // Create an array with points  
                                    var points = [  
                                       new GLatLng(24.85229, 67.01703),  
                                       new GLatLng(24.914463, 67.0965958),  
                                       new GLatLng(24.86588, 67.06089),  
                                       new GLatLng(24.9726753, 67.06638),
                                       new GLatLng(24.840023, 67.24285),
                                       new GLatLng(24.85229, 67.01703)
                                    ];  
    
                                    // Create a new polyline  
                                    window.polyline = new GPolyline(points, '#ff0000', 5, 0.7);  
                                    GEvent.addListener(window.polyline, 'click', function() {
                                        window.polyline.setOptions(options: { strokeColor: 'blue' });
                                    });
                                    // Add the polyline to the map using map.addOverlay()  
                                    map.addOverlay(window.polyline);                          
                                  }
                                }
                            </script> ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

--edited for clarity (hopefully) I have an XML file that looks something like this:
I have a Perl script that outputs text. I want to import this text
I have a login script that does this: $_SESSION['username']=$username; $_SESSION['password']=$password; If the user logged
I have some script that takes a form and sends it to php using
I have this simple captcha script from online. I like it, and I edited
I have a JavaScript resource that has the possibility of being edited at any
I have a bunch of different objects that are commonly edited in the same
NOTE: EDITED The real-world situation is a series of events that each have two
I have a jQuery accordion from this site and edited for my purposes, but
I have this script . Element with class "help" and id "help" overlap each

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.