Google 지도 중국어 A...login
Google 지도 중국어 API 매뉴얼
작가:php.cn  업데이트 시간:2022-04-14 16:36:56

Google 지도 이벤트


Google MapsEvents


마커를 클릭하면 지도가 확대됩니다. 이벤트는 Google 지도에 연결됩니다.


지도를 확대하려면 표시를 클릭하세요

우리는 이전 기사에서 사용한 영국 런던 지도를 계속 사용합니다.

사용자가 마크를 클릭하면 지도가 확대되는 기능을 구현합니다(마크를 클릭하면 지도 확대/축소 이벤트 바인딩).

코드는 다음과 같습니다.

Instance

<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script>
var myCenter=new google.maps.LatLng(51.508742,-0.120850);

function initialize()
{
var mapProp = {
  center: myCenter,
  zoom:5,
  mapTypeId: google.maps.MapTypeId.ROADMAP
  };

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

var marker = new google.maps.Marker({
  position: myCenter,
  title:'Click to zoom'
  });

marker.setMap(map);

// Zoom to 9 when clicking on marker
google.maps.event.addListener(marker,'click',function() {
  map.setZoom(9);
  map.setCenter(marker.getPosition());
  });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>

</body>
</html>

인스턴스 실행 »

온라인 인스턴스를 보려면 "인스턴스 실행" 버튼을 클릭하세요.

addListener() 이벤트 핸들러를 사용하여 리스너를 등록하세요. 이벤트. 이 메서드는 개체와 이벤트를 사용하여 지정된 이벤트가 발생할 때를 수신합니다. 함수가 호출됩니다.


Reset marker

지도에 이벤트 핸들러를 추가하여 'center' 속성을 변경합니다. 다음 코드는 center_changed 이벤트를 사용하여 3초 후에 중심점을 표시합니다.

Example

<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script>
var myCenter=new google.maps.LatLng(51.508742,-0.120850);

function initialize()
{
var mapProp = {
  center: myCenter,
  zoom:5,
  mapTypeId: google.maps.MapTypeId.ROADMAP
  };

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

var marker = new google.maps.Marker({
  position: myCenter,
  title:'Click to zoom'
  });

marker.setMap(map);

// Zoom to 9 when clicking on marker
google.maps.event.addListener(marker,'click',function() {
  map.setZoom(9);
  map.setCenter(marker.getPosition());
  });
     
google.maps.event.addListener(map,'center_changed',function() {
// 3 seconds after the center of the map has changed, pan back to the marker
  window.setTimeout(function() {
    map.panTo(marker.getPosition());
  },3000);
  });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>

</body>
</html>

Run 예시 »

온라인 인스턴스를 보려면 "인스턴스 실행" 버튼을 클릭하세요



마크를 클릭하면 정보 창이 열립니다.

정보 창에 일부 텍스트 정보를 표시하려면 표시를 클릭하세요.

Instance

<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script>
var myCenter=new google.maps.LatLng(51.508742,-0.120850);

function initialize()
{
var mapProp = {
  center:myCenter,
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };

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

var marker=new google.maps.Marker({
  position:myCenter,
  });

marker.setMap(map);

var infowindow = new google.maps.InfoWindow({
  content:"Hello World!"
  });

google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
  });
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>

인스턴스 실행»

온라인 인스턴스를 보려면 "인스턴스 실행" 버튼을 클릭하세요



표시 설정 그리고 각 마크의 정보를 엽니다 Window

사용자가 지도를 클릭하면 윈도우를 실행합니다

사용자가 지도의 특정 위치를 클릭하면 placeMarker() 함수를 사용하여 지정된 위치에 마커를 배치하고 팝업합니다. 정보 창 표시:

Instance

<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script>
var map;
var myCenter=new google.maps.LatLng(51.508742,-0.120850);

function initialize()
{
var mapProp = {
  center:myCenter,
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };

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

  google.maps.event.addListener(map, 'click', function(event) {
    placeMarker(event.latLng);
  });
}

function placeMarker(location) {
  var marker = new google.maps.Marker({
    position: location,
    map: map,
  });
  var infowindow = new google.maps.InfoWindow({
    content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
  });
  infowindow.open(map,marker);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>

</body>
</html>

인스턴스 실행 중 »

온라인 인스턴스를 보려면 "인스턴스 실행" 버튼을 클릭하세요.



Google 지도 - 이벤트 참조 매뉴얼

Google Maps API 참조 매뉴얼 .

PHP 중국어 웹사이트