Reputation: 55
How can i display markers on this map i created? .Marker("1.2233424, 4.865876)
won't work form me?
@using Jmelosegui.Mvc.GoogleMap
<div class="row">
<div class="col-md-12">
@(Html.GoogleMap()
.Name("map")
.Height(400)
.Width(700)
)
</div>
</div>
Upvotes: 1
Views: 1300
Reputation: 2281
In order to get multiple markers on the same map you will want to use the bounds method. This example uses 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);
The map.fitBounds(bounds) will just center the map between your markers so all markers will be on the screen.
Upvotes: 1
Reputation: 355
You need to add .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!"))
Source: jmelosegui docs
Upvotes: 1
Reputation: 39413
Your syntax it's wrong. You need to use
.Markers(m => m.Add().Title("Hello World!"))
Check the documentation to learn more
Upvotes: 1