تعديل حدود البحث المحلي في السياق

يمكنك تغيير معلمة locationRestriction للبحث عن الأماكن LocalContextMapView من الإعداد التلقائي من خلال الالتزام الصارم بإطار عرض الخريطة. في هذا المثال، تم ضبط حدود locationRestriction لتكون أكبر بكثير من إطار عرض الخريطة الأولي. جرّب النقر على مكان في أداة اختيار المكان لمشاهدة حركة الخريطة لعرض المكان المحدّد.

فهم الرمز

تحديد حدود البحث عن السياق المحلي

حدِّد حدود البحث الصارم locationRestriction باستخدام السمة LatLngBounds. يستخدم هذا المثال واجهة 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 },
});

JavaScript

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

عندما تقع نقطة اهتمام محدّدة (POS) خارج إطار العرض الحالي، يتم عرض عرض الخريطة المحلية تلقائيًا لعرض نقطة الاهتمام هذه ضمن الحدود المرئية بدون الحاجة إلى أي رمز لإدارة الخريطة.

إذا لم تحدِّد نقطة انطلاق لخاصية directionsOptions في LocalContextMapView، سيتم نقل الخريطة لعرض نقطة الاهتمام المحدّدة فقط.

إذا حدّدت directionsOptions بنقطة الانطلاق، ستعرض الخريطة كلاً من نقطة الانطلاق ونقطة الاهتمام المحدّدة، إلى جانب مسار المشي بين النقطتين.

TypeScript

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

JavaScript

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

تجربة عيّنة من المحتوى