استرداد الحقول
إذا كان لديك كائن Place أو معرّف مكان حالي، استخدِم طريقة Place.fetchFields()
للحصول على تفاصيل حول هذا المكان. قدِّم قائمة مفصولة بفواصل لحقول بيانات الأماكن المطلوب عرضها، وحدِّد أسماء الحقول بتنسيق camel case. استخدِم الكائن Place الذي تم عرضه للحصول على بيانات الحقول المطلوبة.
يستخدم المثال التالي رقم تعريف مكان لإنشاء Place جديد، ويطلب Place.fetchFields() الحقلَين displayName وformattedAddress، ويضيف علامة إلى الخريطة، ويسجّل بعض البيانات في وحدة التحكّم.
TypeScript
async function getPlaceDetails() { const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary; const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary; // Use place ID to create a new Place instance. const place = new Place({ id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg', requestedLanguage: 'en', // optional }); // Call fetchFields, passing the desired data fields. await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] }); // Log the result console.log(place.displayName); console.log(place.formattedAddress); // Add an Advanced Marker const marker = new AdvancedMarkerElement({ map, position: place.location, title: place.displayName, }); }
JavaScript
async function getPlaceDetails() { const { Place } = await google.maps.importLibrary("places"); const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); // Use place ID to create a new Place instance. const place = new Place({ id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg', requestedLanguage: 'en', // optional }); // Call fetchFields, passing the desired data fields. await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] }); // Log the result console.log(place.displayName); console.log(place.formattedAddress); // Add an Advanced Marker const marker = new AdvancedMarkerElement({ map, position: place.location, title: place.displayName, }); }
Map وPlace قبل هذه الدالة:
const { Map } = await google.maps.importLibrary("maps"); const { Place } = await google.maps.importLibrary("places");