Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i m designing a website in which i am using Google map api for showing map and multiple markers of different locations on map . The latitude and longitude are save in my database and in a for loop i m calling a javascript function in which markers are created.The main problem is that the function is calling on each iteration but the marker on the map is shows of only first record .I am using function

Page.ClientScript.RegisterStartupScript(this.GetType(), i.ToString(), "getpoint(" + ds.Tables[0].Rows[i]["Latitude"] + "," + ds.Tables[0].Rows[i]["Longitude"] + "," + str1 + "," + str2 + "," + str3 + ");", true);

to call javascript function getpoint(),the code of function is given below:
function createMarker(point, html) {
            map = new GMap2(document.getElementById("map_canvas"));
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function () {
            return marker;

        function getpoint(lat,lon, image, name, adress)
            if (GBrowserIsCompatible())
                //  map = new GMap2(document.getElementById("map_canvas"));
                point = new GLatLng(lat, lon);
                marker = createMarker(point, '<table><tr><td> <a href="/KB/answers/umaid.aspx"><img src=' + image + ' width=50 height=50 vspace=0 hspace=10 align=left/><\/a></td><td valign=top>' + name + '<br/>' + adress + '</td></tr></table>')
                map.setCenter(new GLatLng(26.2816, 73.0232), 13);

Please help me as soon as possible.

Updated 20-Apr-10 1:26am

1 solution

I don't know much about the Maps API (I had a play for a few hours one day....thats the stretch of it), but your createMarker function is creating a new map everytime it is called. The map should be only created when the page is initially loaded.

Doesn't look right to me.

nishi2010 wrote:
function createMarker(point, html) {
map = new GMap2(document.getElementById("map_canvas"));
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900