I want to retrieve addresses supplied in a database and on page load, have a map be populated with markers at the location of those addresses.
I can get the information from the database, but I can't figure out how to call the showAddress function and pass in the value of the address..

Currently, I have a textbox and button on the page. Input an address, click the button, and a marker will show at that address.
This is the code I have for that.. (this is in my .cs file):

string script = @"<script src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA' type='text/javascript'></script>
        <script type='text/javascript'>
            var map = null;
            var geocoder = null;
            
            function initialize() {
                if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById('map_canvas'));
                map.addControl(new GLargeMapControl3D());
                map.setCenter(new GLatLng(42.663, -73.787), 13);
                geocoder = new GClientGeocoder();
                }
            }

            function showAddress(address) {
                if (geocoder) {
                    geocoder.getLatLng(
                        address,
                        function(point) {
                            if (!point) {
                                alert(address + ' not found');
                            } else {
                            map.setCenter(point, 13);
                            var marker = new GMarker(point);
                            map.addOverlay(marker);
                            marker.openInfoWindowHtml(address);
                            }
                        }
                    );
                }
            }
        </script>";

        Page.ClientScript.RegisterStartupScript(this.GetType(), "js", script, false);

Then I retrieve the data and put the addresses into a list.
And here, I use a for loop to get the addresses and attempt to call the showAddress function, and this is the part I'm having trouble with..

for (int i = 0; i < list.Count; i++)
        {
            string display = @"<script language='javascript'>showAddress(" + list[i].Address + ");</script>";

            Page.ClientScript.RegisterStartupScript(this.GetType(), "dis", display, false);
        }

Am I able to call a javascript function from another section of my code or no?
How would I go about doing this?

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.