로컬 컨텍스트 검색 경계 조정

LocalContextMapView 장소 검색의 locationRestriction 매개변수를 지도 표시 영역으로 엄격하게 제한되는 기본값에서 변경할 수 있습니다. 이 예에서는 locationRestriction의 경계를 지도의 초기 표시 영역보다 훨씬 더 크게 설정합니다. 지도가 선택된 장소를 표시하기 위해 이동하는 것을 보려면 장소 선택기에서 한 장소를 클릭해보세요.

코드 이해

로컬 컨텍스트 검색 경계 지정

LatLngBounds 속성을 사용하여 엄격한 locationRestriction 검색 경계를 정의합니다. 이 예에서는 LatLngBoundsLiteral 인터페이스를 사용하여 LatLngBounds 객체를 만듭니다.

TypeScript

const bigBounds = {
  north: 37.432,
  south: 37.412,
  west: -122.094,
  east: -122.074,
};
const localContextMapView = new google.maps.localContext.LocalContextMapView({
  element: document.getElementById("map"),
  placeTypePreferences: [{ type: "restaurant" }],
  maxPlaceCount: 12,
  locationRestriction: bigBounds,
  directionsOptions: { origin: center },
});

자바스크립트

const bigBounds = {
  north: 37.432,
  south: 37.412,
  west: -122.094,
  east: -122.074,
};
const localContextMapView = new google.maps.localContext.LocalContextMapView({
  element: document.getElementById("map"),
  placeTypePreferences: [{ type: "restaurant" }],
  maxPlaceCount: 12,
  locationRestriction: bigBounds,
  directionsOptions: { origin: center },
});

로컬 컨텍스트 지도 표시 영역과 directionsOptions의 관계

선택된 관심 장소가 현재 표시 영역 범위를 벗어나면 지도를 관리하기 위한 코드가 없어도 로컬 컨텍스트 지도 보기가 자동으로 이동하여 보이는 경계 내에 해당 관심 장소를 표시합니다.

LocalContextMapViewdirectionsOptions 속성에 출발지를 지정하지 않으면 선택된 관심 장소만 표시하도록 지도가 이동합니다.

출발지와 함께 directionsOptions를 지정하면 지도에 출발지와 선택된 관심 장소가 두 지점 사이의 도보 경로와 함께 표시됩니다.

TypeScript

const localContextMapView = new google.maps.localContext.LocalContextMapView({
  element: document.getElementById("map"),
  placeTypePreferences: [{ type: "restaurant" }],
  maxPlaceCount: 12,
  locationRestriction: bigBounds,
  directionsOptions: { origin: center },
});

자바스크립트

const localContextMapView = new google.maps.localContext.LocalContextMapView({
  element: document.getElementById("map"),
  placeTypePreferences: [{ type: "restaurant" }],
  maxPlaceCount: 12,
  locationRestriction: bigBounds,
  directionsOptions: { origin: center },
});

샘플 사용해 보기