在Google地图上显示多个标记,这些标记具有从C#中的SQL Server数据库检索到的纬度和经度值

问题描述:

我有一个表,其中存储了纬度和经度值的列表.我现在要做的是从表格中检索所有这些值,并在Google Maps版本3中显示多个标记.

I have a table where I have a list of latitude and longitude values stored. What I want to do now is to retrieve all those values from the table and display multiple markers on Google maps version 3.

我不知道如何进行.在搜索网络时,我遇到了JSON,但我对此一无所知.请帮忙!

I have no idea about how to proceed. While searching the net I came across JSON but I have no knowledge about it. Please help!

 //C#
    [WebMethod]
    public static List<Marker> RetrieveMarker()
    {
        List<Marker> markers = new List<Marker>();


        //Here you should have your table with data from database.

        for (int i = 0; i < tableMarker.Rows.Count; i++)
        {              


            Marker marker = new Marker();
            marker.ID = Convert.ToInt32(tableMarker.Rows[i]["IDmarker"]);
            marker.Latitud = Convert.ToDouble(tableMarker.Rows[j]["latitud"]);
            marker.Longitud = Convert.ToDouble(tableMarker.Rows[j]["longitud"]);


            markers.Add(marker);
        }
            //Return list of Marker object ,  javascript you receive Array of object

        return markers;
    }



    public class Marker
    {
        public int ID;
        public double Latitud;
        public double Longitud;
    }
    //C#

    //JavaScript
    var map;
    function InicializarMapa() {

        map = new google.maps.Map(document.getElementById('map_canvas'), {
            zoom: 10,
            center: new google.maps.LatLng(-32.960795281527304, -60.66179810739743), //change this
            zoomControl: true
        });

        google.maps.event.addDomListener(window, 'load', ReloadMarker);

    }

    function ReloadMarker(){
        PageMethods.RetrieveMarker(onSuccessRetrieveMarker);
    }

    function onSuccessRetrieveMarker(array of object from code behind (markers))
    {
         for (var i = 0; i < markers.length; i++) {
              var myLatlng = new google.maps.LatLng(markers[i].Latitud,markers[i].Longitud);
              var marker = new google.maps.Marker({
              position: myLatlng,
              map: map,
              title: 'Hello World!'
            });
         }
         marker.setMap(map);

    }
    //JavaScript

您需要从aspx启用pagemethos,我希望您至少使用了一些代码或逻辑 对不起,我的英语

You need to enable pagemethos from the aspx , i hope you used some code or logic at least Sorry for my English