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

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

כברירת מחדל, נקודות עניין (POI) מופיעות במפה הבסיסית עם הסמלים המתאימים שלהן. נקודות העניין כוללות פארקים, בתי ספר, בנייני ממשלה ועוד. כמו כן, נקודות עניין עסקיות מופיעות במפה כברירת מחדל כשסוג המפה הוא 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 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
      

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

נקודות עניין מופיעות במפה כברירת מחדל, אבל לא קיימת ברירת מחדל לממשק משתמש בלחיצה (ה-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.
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" }
    ]
  }
]

לפרטים נוספים, אפשר לעיין במדריך להסתרת תכונות במפה באמצעות עיצוב.