Показать сообщение отдельно
  #3 (permalink)  
Старый 18.02.2015, 00:54
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

Google map центрирование
psfdek,
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Region code biasing (US)</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    div ~  a{
        display:  inline-block;
        cursor: pointer;
         margin: 0 15px;
         background: #FFCC99 ;
         padding: 4px 8px;
      }
    div ~ a:hover{
       background: #CCCCCC
     }

    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>
var geocoder;
var map;
var query = new Array( 'Челябинск, ул. Кирова, д. 149', 'Челябинск, ул. Кирова, д. 86', 'Челябинск, ул. Кирова, д. 112');
function initialize() {
  geocoder = new google.maps.Geocoder();
  var mapOptions = {
    zoom: 15
  }
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  codeAddress();
}

function codeAddress() {
	var count=0;
	for (var i = 0; i < query.length; i++) {
		var address = query[count];
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
var a = document.createElement('a');
a.appendChild(document.createTextNode(results[0].address_components[1].short_name+', '+results[0].address_components[0].short_name));
a.onclick = function() {
           map.setZoom(17);
           map.setCenter(results[0].geometry.location);

}
document.body.appendChild(a);
				map.setCenter(results[0].geometry.location);
				var marker = new google.maps.Marker({
				  map: map,
				  position: results[0].geometry.location
				});
			} else {
				alert('Geocode was not successful for the following reason: ' + status);
			}
		});
		count++;
	}
}

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

    </script>
  </head>
  <body>
   <div id="map-canvas"  style="width: 600px; height: 400px"></div>
  </body>
</html>

Последний раз редактировалось рони, 18.02.2015 в 00:57.
Ответить с цитированием