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