تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
في هذا المثال، نضيف شريط البحث الإكمال التلقائي لمكان
للعناوين للسماح للمستخدم بإدخال عنوان وتقييم
وسائل الراحة القريبة. بالنسبة إلى المستخدمين المقيمين، تم ضبط placeTypePreferences
على الأنواع المرتبطة عادةً بالحياة المنزلية. تقتصر العناوين الواردة في هذه العينة
على الولايات المتحدة.
/*
* 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;
}
input {
height: 30px;
margin: 12px 0px;
padding: 10px;
width: 300px;
}
<html>
<head>
<title>Local Context Home</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>
<input id="input" placeholder="Enter a US address" />
<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.
See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
for more information.
-->
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&libraries=localContext,places&v=beta"
defer
></script>
</body>
</html>
عند تحديد أنواع الأماكن التي تريد عرضها في "مكتبة السياق المحلية"، يمكنك تخصيص وزن نسبي لكل خاصية باستخدام السمة weight (تظهر الأنواع التي لها ترجيح نسبي أعلى مرات أكثر). يحدد هذا المثال معدل تكرار أعلى للحدائق والمدارس إن توفر.
لاستخدام خدمة الإكمال التلقائي للأماكن، يجب أولاً تحميل مكتبة الأماكن، وواجهة برمجة تطبيقات JavaScript للخرائط.
توضّح مستندات Autocomplete جميع المعلَمات المتاحة لتخصيص سلوك الإكمال التلقائي الخاص بالأماكن،
مثل فلترة عبارات البحث المقترحة حسب الموقع الجغرافي أو نوع المكان.
اتّبِع مستندات Autocomplete
ونماذج الرموز للتعرّف
على كيفية إضافة شريط بحث لميزة "الإكمال التلقائي" للأماكن إلى موقعك الإلكتروني أو خريطتك. في هذا المثال، الأسطر ذات الصلة هي:
TypeScript
// Build and add the Autocomplete search bar
const input = document.getElementById("input")! as HTMLInputElement;
const options = {
types: ["address"],
componentRestrictions: {
country: "us",
},
fields: ["address_components", "geometry", "name"],
};
const autocomplete = new google.maps.places.Autocomplete(input, options);