بشكل افتراضي، تظهر نقاط الاهتمام على الخريطة الأساسية مع الأيقونات المقابلة لها. تشمل نقاط الاهتمام الحدائق والمدارس والمباني الحكومية والمزيد. وبالإضافة إلى ذلك، تظهر نقاط الاهتمام للأنشطة التجارية بشكل افتراضي على الخريطة عندما يكون نوع الخريطة هو kGMSTypeNormal
. تمثل نقاط الاهتمام الخاصة بالأنشطة التجارية أنشطة تجارية مثل المتاجر
والمطاعم والفنادق وغيرها.
تقابل نقطة الاهتمام رقم تعريف المكان، على النحو المحدّد في حزمة تطوير البرامج للأماكن المخصّصة لنظام التشغيل iOS. على سبيل المثال، تعتبر الحدائق الترفيهية نقاط اهتمام، لكن لا تُعد أشياء مثل نافورات المياه نقاط اهتمام (ما لم تكن ذات أهمية وطنية أو تاريخية).
الاستماع إلى أحداث النقر على نقاط الاهتمام
إذا كنت تريد الردّ على مستخدم ينقر على نقطة اهتمام، نفِّذ GMSMapViewDelegate
ونفِّذ طريقة
mapView(_:didTapPOIWithPlaceID:name:location:)
كما هو موضّح في المثال التالي:
Swift
import GoogleMaps class POI: UIViewController, GMSMapViewDelegate { override func loadView() { let camera = GMSCameraPosition.camera( withLatitude: 47.603, longitude:-122.331, zoom:14 ) let mapView = GMSMapView.map(withFrame: .zero, camera: camera) mapView.delegate = self self.view = mapView } func mapView( _ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D ) { print("You tapped \(name): \(placeID), \(location.latitude)/\(location.longitude)") } }
Objective-C
#import "POI.h" @import GoogleMaps; @interface POI () <GMSMapViewDelegate> @end @implementation POI - (void)loadView { GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:47.603 longitude:-122.331 zoom:14]; GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView.delegate = self; self.view = mapView; } #pragma mark - GMSMapViewDelegate - (void)mapView:(GMSMapView *)mapView didTapPOIWithPlaceID:(NSString *)placeID name:(NSString *)name location:(CLLocationCoordinate2D)location { NSLog(@"You tapped %@: %@, %f/%f", name, placeID, location.latitude, location.longitude); } @end
عرض التفاصيل في نافذة معلومات
تظهر نقاط الاهتمام على الخريطة تلقائيًا، ولكن لا توجد واجهة مستخدم تلقائية عند النقر (لا تعرض واجهة برمجة التطبيقات نافذة معلومات أو أي واجهة مستخدم أخرى تلقائيًا عندما ينقر المستخدم على إحدى نقاط الاهتمام). يوضح المثال التالي كيفية استخدام علامة لعرض نافذة معلومات لنقطة اهتمام:
Swift
// Declare GMSMarker instance at the class level. let infoMarker = GMSMarker() // Attach an info window to the POI using the GMSMarker. func mapView( _ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D ) { infoMarker.snippet = placeID infoMarker.position = location infoMarker.title = name infoMarker.opacity = 0; infoMarker.infoWindowAnchor.y = 1 infoMarker.map = mapView mapView.selectedMarker = infoMarker }
Objective-C
// Declare a GMSMarker instance at the class level. GMSMarker *infoMarker; // Attach an info window to the POI using the GMSMarker. - (void)mapView:(GMSMapView *)mapView didTapPOIWithPlaceID:(NSString *)placeID name:(NSString *)name location:(CLLocationCoordinate2D)location { infoMarker = [GMSMarker markerWithPosition:location]; infoMarker.snippet = placeID; infoMarker.title = name; infoMarker.opacity = 0; CGPoint pos = infoMarker.infoWindowAnchor; pos.y = 1; infoMarker.infoWindowAnchor = pos; infoMarker.map = mapView; mapView.selectedMarker = infoMarker; }
جارٍ إيقاف ظهور نقاط الاهتمام على الخريطة
يمكنك إخفاء نقاط الاهتمام من خلال تطبيق أنماط مخصّصة على جميع نقاط الاهتمام أو على فئات معيّنة من نقاط الاهتمام.
يخفي إعلان نمط JSON التالي جميع نقاط الاهتمام للنشاط التجاري على الخريطة:
[
{
"featureType": "poi.business",
"stylers": [
{ "visibility": "off" }
]
}
]
كمثال آخر، يعمل تنسيق JSON التالي على تبسيط عرض جميع فئات نقاط الاهتمام:
[
{
"featureType": "poi",
"stylers": [
{ "visibility": "simplified" }
]
}
]
لمزيد من التفاصيل، راجِع دليل إخفاء ميزات الخريطة باستخدام التصميم.