(MVC)从 MapView 的控制器获取纬度、经度? C#

(MVC) Get Latitude, Longitude from Controller for the MapView? c#

大家好,我有一个这样的模型(位置):

namespace moBelegDAL.Models
{
    public class Position : Entity
    {
        public int PositionId { get; set; }
        public string EmployeeName { get; set; }
        public string EmployeeNumber { get; set; }
        public int CompanyId { get; set; }
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public double Accuracy { get; set; }
        public double Altitude { get; set; }
        public bool AltitudeValid { get; set; }
        public double Heading { get; set; }
        public bool HeadingValid { get; set; }
        public double Speed { get; set; }
        public bool SpeedValid { get; set; }
        public double NumSatellites { get; set; }
        public bool NumSatellitesValid { get; set; }
        public DateTime Timestamp { get; set; }
    }
}

大家好,我有一个这样的控制器 (LocationController):

namespace moBelegGUI.Controllers
{
    [Authorize]
    public class LocationController : BootstrapBaseController
    {
        public double latitude;
        public double longitude;



        public ActionResult OverView(Position position)
        {
            latitude = position.Latitude;
            longitude = position.Longitude;
            ViewBag.Latitude = latitude;
            ViewBag.Longitude = longitude;
            return View();
        }
    }
}

我有这样的视图 (OverView):

<body onload="GetMap();">

    <script type="text/javascript"> function GetMap() { }</script>
    <script type="text/javascript">

    function GetMap() {

        var latitude = @ViewBag.Latitude;
        var longitude = @ViewBag.Longitude;


        // Set the map and view options, setting the map style to Road and
        // removing the user's ability to change the map style
        var mapOptions =
            {
                credentials: "Al64oUurZOV-AyLUdQI0i0BSPC76kcJc4M2rmA9rSi8VtKhu0GH-qBjVhu4AlzvE",
                height: 400, width: 960, mapTypeId: Microsoft.Maps.MapTypeId.road,

                //Edit the Views of the Map
                showMapTypeSelector: true,
                enableSearchLogo: false,
                enableClickableLogo: false,
                showDashboard: true
            };

        // Initialize the map
        var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);

        //Hardcode Location with Marker
        var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(latitude, longitude), null);
        map.entities.push(pushpin);
        Microsoft.Maps.Events.addHandler(pushpin, "mouseup", ZoomIn);

        //Function for zoom to the Marker
        function ZoomIn(e) { }


    }

    </script>
    <asp:Literal ID="Literal1" runat="server">
    </asp:Literal>

</body>

概览只是一张带有硬编码位置的 Bing 地图。 我怎样才能从我的模型的概览中获得正确的位置(纬度、经度)。

我从控制器传递数据的方法是这样的

 public ActionResult OverView(Position position)
        {
             latitude = position.Latitude;
             longitude = position.Longitude;

             //Passing the latitude and longitude values of last element in latitude and longitude lists
             ViewBag.Latitude = latitude;
             ViewBag.Longitude = longitude;
             return View();
        }

JavaScript 就像:

<body onload="GetMap();">

    <script type="text/javascript"> function GetMap() { }</script>
    <script type="text/javascript">

    function GetMap() {

        var latitude = @ViewBag.Latitude;
        var longitude = @ViewBag.Longitude;

        // Set the map and view options, setting the map style to Road and
        // removing the user's ability to change the map style
        var mapOptions =
            {
                credentials: "Al64oUurZOV-AyLUdQI0i0BSPC76kcJc4M2rmA9rSi8VtKhu0GH-qBjVhu4AlzvE",
                height: 400, width: 960, mapTypeId: Microsoft.Maps.MapTypeId.road,

                //Edit the Views of the Map
                showMapTypeSelector: true,
                enableSearchLogo: false,
                enableClickableLogo: false,
                showDashboard: true
            };

        // Initialize the map
        var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);

        //Hardcode Location with Marker
        var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(latitude, longitude), null);
        map.entities.push(pushpin);
        Microsoft.Maps.Events.addHandler(pushpin, "mouseup", ZoomIn);

        //Function for zoom to the Marker
        function ZoomIn(e) { }


    }

    </script>
    <asp:Literal ID="Literal1" runat="server">
    </asp:Literal>

</body>