уже не актуально.
При нажатии на кнопку "setMarkers", карту перекидывает к установленным маркерам, надеюсь кому-нибудь поможет:
<!DOCTYPE html>
<html>
<head>
<title>Remove Markers</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src="main.js"></script>
</head>
<body>
<div id="panel">
<input onclick="setM();" type=button value="setMarkers">
<input onclick="showMarkers();" type=button value="Show All Markers">
<input onclick="deleteMarkers();" type=button value="Delete Markers">
<input onclick="goMarker();" type=button value="Go to Marker">
</div>
<div id="map-canvas"></div>
<p>Click on the map to add markers.</p>
</body>
</html>
var map;
function initialize() {
var mapOptions = {
zoom: 6,
center: new google.maps.LatLng(-35.9, 155.2)
}
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
var beaches = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
function setMarkers(map, locations) {
// Add markers to the map
var latlngbounds = new google.maps.LatLngBounds();
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
latlngbounds.extend(myLatLng);
var marker = new google.maps.Marker({
position: myLatLng,
map: map
});
}
map.setCenter( latlngbounds.getCenter(), map.fitBounds(latlngbounds));
}
function setM(){
setMarkers(map, beaches);
}
google.maps.event.addDomListener(window, 'load', initialize);