i've tried using google maps marker manager, but i seem to be hitting a brick wall everytime, i follow the tutorials on how to create markermanager on google documentation, but it seems nothing is working for me, is it a problem in how my code is written? running out of ideas here, at the moment i have set ONE marker to drop down on the map based on latlng.
can someone please try like implementing the tutorial code and find a working solution for me? its driving me mad.
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div id="map_canvas" style="width:500px; height:500px;"></div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
@*<script src="../../Scripts/markermanager.js" type="text/javascript"></script>*@
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP // map view, can be set to satellite, street, roadview, aerialview
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
animation: google.maps.Animation.DROP,
title: "Uluru (Ayers Rock)"
});
marker.setMap(map);
}
$(document).ready(function () {
initialize();
});
</script>
2048 characters in URL is just under 100 GeoCode values. So, again no more than 100 markers.
Here is an example to get you started:
var map;
var mgr;
function initialize() {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
mgr = new MarkerManager(map);
google.maps.event.addListener(mgr, "loaded", function() {
for (var i = 0; i < 1000; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(Math.random() * 180 - 90, Math.random() * 360 - 180),
title: "Random marker #" + i
});
mgr.addMarker(marker, 0);
}
mgr.refresh();
});
}
google.maps.event.addDomListener(window, "load", initialize);
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markermanager/src/markermanager.js"></script>
<div id="map_canvas" style="height: 400px;"></div>
<p>Pan or zoom out to see markers</p>
Notice that when creating a marker, I did not specify map: map
or marker.setMap(map)
. Instead, the markers are added to the marker manager which in turn adds them to the map when you call markermanager.refresh()
.
Also note that I've added all markers on the zoom level 0
. Ideally you should load few markers on lower zoom levels and more markers on higher zoom levels.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With