تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
في ما يلي عرض خريطة الخريطة المحلية الأساسية بدون تخصيصات.
نحدّد الخصائص المطلوبة الخاصة بمكتبة السياقات المحلية، مثل placeTypePreferences وmaxPlaceCount، بالإضافة إلى سمات Map الأساسية في center وzoom.
/*
* Always set the map height explicitly to define the size of the div element
* that contains the map.
*/
#map {
height: 100%;
}
/*
* Optional: Makes the sample page fill the window.
*/
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
<html>
<head>
<title>Local Context Basic</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="map"></div>
<!--
The `defer` attribute causes the callback to execute after the full HTML
document has been parsed. For non-blocking uses, avoiding race conditions,
and consistent behavior across browsers, consider loading using Promises
with https://www.npmjs.com/package/@googlemaps/js-api-loader.
-->
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&libraries=localContext&v=beta"
defer
></script>
</body>
</html>
بدلاً من الفئة google.maps.Map، يتم تمثيل خريطة السياق المحلية بالفئة google.maps.localContext.LocalContextMapView. المعلمات الثلاثة المطلوبة في دالة الإنشاء LocalContextMapView هي العنصر في نموذج كائن المستند (DOM) الذي سيكون حاوية عرض الخريطة، وقائمة بالأنواع المراد تضمينها، والحد الأقصى لعدد نتائج الأماكن المراد عرضها.
يتم تحديد حدود locationRestriction التلقائية للبحث عن الأماكن من خلال إطار عرض الخريطة. يتم إنشاء إطار عرض الخريطة عند الاستدعاء الأول إلى
google.maps.localContext.LocalContextMapView.map.setOptions() عندما يتم تحديد مستوى الوسط والتكبير/التصغير لتحميل الخريطة.