עסקים ונקודות עניין אחרות

בחירת פלטפורמה: Android iOS JavaScript

כברירת מחדל, נקודות עניין מופיעות במפת הבסיס יחד עם הסמלים המתאימים שלהן. נקודות עניין כוללות פארקים, בתי ספר, מבני ממשלה ועוד. בנוסף, נקודות עניין של עסקים מופיעות כברירת מחדל במפה כשסוג המפה הוא kGMSTypeNormal. נקודות עניין של עסקים מייצגות עסקים כמו חנויות, מסעדות, מלונות ועוד.

נקודת עניין תואמת למזהה מקום, כפי שמוגדר ב-Places SDK ל-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 options = GMSMapViewOptions()
    options.camera = camera
    let mapView = GMSMapView(options: options)
    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];
  GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init];
  options.camera = camera;
  GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options];
  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
      

הצגת פרטים בחלון מידע

נקודות עניין מופיעות במפה כברירת מחדל, אבל אין ממשק משתמש שמוגדר כברירת מחדל בלחיצה (ה-API לא מציג באופן אוטומטי חלון מידע או ממשק משתמש אחר כשהמשתמש לוחץ על נקודת עניין). הדוגמה הבאה ממחישה איך להשתמש בסמן כדי להציג חלון מידע של נקודת עניין:

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.
static 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" }
    ]
  }
]

פרטים נוספים זמינים במדריך בנושא הסתרת מאפייני מפה באמצעות עיצוב.