MVC5上的Google Map API

试图在地图上为多个地址生成多个标记时遇到问题。 所以基本上,我从我的数据库中提取地址,让GoogleLocationService()检测它的坐标。 虽然我不确定如何传递VIEW(.CSHTML)的多个经纬度。 我仍然是MVC的新手,所以我有点麻烦从控制器传递值来查看。 有什么建议么?

在我的代码(控制器)上:

   public ActionResult Index() {

        VerifyUserModel user = new VerifyUserModel();
        user.UserName = "Kenneth Baleda";
        user.AccountLevel = "MGR";

        foreach (string w in a.Companies.Where(x => x.IsActive == "Active").Where(x => x.CompanyName != "tbd").Where(x => x.FullCompanyName != "Test")
                    .Where(x => x.FullCompanyName != "")
                    .Select(x => x.Address).ToArray())
        {
            user.CompanyAddress = w;
            var location = new GoogleLocationService();
            var point = location.GetLatLongFromAddress(w);

            user.Latitude = point.Latitude;
            user.Longtitude = point.Longitude;
        }

            return View(user);
    }

在我的(模型)上:

    public class VerifyUserModel 
    {
    public string UserName { get; set; }

    public string AccountLevel { get; set; }

    public double Latitude { get; set; }

    public double Longtitude { get; set; }

    public string CompanyAddress { get; set; }
}

然后我的(.CSHTML):

@foreach(var place in Model){var latlng = new google.maps.LatLng(@ Model.Latitude,@ Model.Longtitude); var marker = new google.maps.Marker({position:latlng,map:map,title:'Latitude:'+ latlng.Ya +'Longitude:'+ latlng.Za,draggable:true,icon:image}); infoWindow = new google.maps.InfoWindow({content:“ - Test Address - ”}); infoWindow.open(map,marker); geocoder = new google.maps.Geocoder(); //拖动标记时更新邮政地址google.maps.event.addListener(marker,'click',function(){// dragend geocoder.geocode({latLng:marker.getPosition()},function(responses){ if(responses && responses.length> 0){infoWindow.setContent(“”+ responses [0] .formatted_address +“
“+”Latitude:“+ marker.getPosition()。lat()+”&nbsp“+”Longitude:“+ marker.getPosition()。lng()+”“); infoWindow.open(map,marker);}其他{alert('错误:谷歌地图无法确定此位置的地址。');}}); map.panTo(marker.getPosition());}); //关闭标记窗口被拖动谷歌时。 maps.event.addListener(marker,'dragstart',function(){infoWindow.close(map,marker);});}

链接地址: http://www.djcxy.com/p/96193.html

上一篇: Google Map API on MVC5

下一篇: Google Maps API V3, Listener is behaving strangely