الأنشطة التجارية ونقاط الاهتمام الأخرى

اختيار النظام الأساسي: Android iOS JavaScript

بشكل افتراضي، تظهر نقاط الاهتمام على الخريطة الأساسية إلى جانب الرموز المقابلة لها. تشمل نقاط الاهتمام الحدائق والمدارس والمباني الحكومية وغيرها. بالإضافة إلى ذلك، تظهر نقاط الاهتمام لـ الأنشطة التجارية بشكل تلقائي على الخريطة عندما يكون نوع الخريطة 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" }
    ]
  }
]

لمزيد من التفاصيل، يمكنك الاطّلاع على دليل إخفاء ميزات الخريطة باستخدام الأنماط.