כברירת מחדל, נקודות עניין (POI) מופיעות במפה הבסיסית עם הסמלים התואמים שלהן. נקודות עניין כוללות פארקים, בתי ספר, מבני ממשל ועוד. בנוסף, נקודות עניין עסקיות מופיעות כברירת מחדל במפה כשסוג המפה הוא kGMSTypeNormal
. נקודות עניין של עסקים מייצגות עסקים כמו חנויות, מסעדות, מלונות ועוד.
נקודת עניין תואמת למזהה מקום, כפי שמוגדר ב-Place 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" }
]
}
]
לפרטים נוספים אפשר לעיין במדריך להסתרת תכונות של המפה באמצעות סגנון.