繁体   English   中英

Visual Studio Visual Studio MVC asp.NET Google Map

[英]Visual Studio Visual Studio MVC asp.NET Google Map

如何在我创建的地图上显示标记? .Marker("1.2233424, 4.865876)不会形成我的作品吗?

@using Jmelosegui.Mvc.GoogleMap
<div class="row">
     <div class="col-md-12">
          @(Html.GoogleMap()
             .Name("map")
             .Height(400)
             .Width(700)
           )
     </div>
</div>

你的语法错了。 你需要使用

.Markers(m => m.Add().Title("Hello World!"))

查看文档以了解更多信息

你需要添加.Center(c => c.Latitude(1.2233424).Longitude(4.865876))

Html.GoogleMap()
            .Name("map")
            .Height(300)
            .Center(c => c.Latitude(1.2233424)
                          .Longitude(4.865876))
            .Markers(m => m.Add().Title("Hello World!"))

资料来源: jmelosegui docs

为了在同一个地图上获得多个标记,您将需要使用bounds方法。 这个例子使用javascript。

HTML

<div itemprop="map" id="googleMap" style="height:400px;width:100%;"></div>


                <script src="https://maps.googleapis.com/maps/api/js"></script>

使用Javascript

var myCenter = new google.maps.LatLng(YourLat, YourLng);
var myCenter2 = new google.maps.LatLng(YourSecondLat, YourSecondLng);

function initialize() {
    var bounds = new google.maps.LatLngBounds(myCenter, myCenter2);
    var mapProp = {
        zoom: 12,
        scrollwheel: false,
        draggable: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);

    var marker = new google.maps.Marker({
        position: myCenter,
        map: map,
    });
    var marker2 = new google.maps.Marker({
        position: myCenter2,
        map: map,
    })
    map.fitBounds(bounds);
}

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

map.fitBounds(bounds)将使您的标记之间的地图居中,以便所有标记都在屏幕上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM