ทำเครื่องหมายเหตุการณ์และท่าทางสัมผัส
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เมื่อตั้งค่าพร็อพเพอร์ตี้เครื่องหมายขั้นสูงที่เฉพาะเจาะจง คุณจะตรวจสอบเหตุการณ์ที่เกิดขึ้นกับเครื่องหมายได้ เช่น การแตะและท่าทางสัมผัส
เมื่อแตะเครื่องหมายจะเห็นข้อมูลเพิ่มเติม เช่น ชื่อเครื่องหมายหรือข้อมูลโค้ด นอกจากนี้ยังย้ายเครื่องหมายที่ลากได้โดยใช้ท่าทางสัมผัสแบบกดค้างได้ด้วย
ตอบสนองต่อเหตุการณ์ที่เกิดขึ้นกับเครื่องหมาย
คุณตอบสนองต่อเหตุการณ์ที่เกิดขึ้นกับเครื่องหมายได้โดยเพิ่มโปรโตคอล GMSMapViewDelegate
ลงในมุมมองและใช้ Callback ที่เกี่ยวข้อง ตัวอย่างนี้จะระบุ title
และ
snippet
สำหรับเครื่องหมายที่เลือก
Swift
// MARK: GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
if let title = marker.title {
if let snippet = marker.snippet {
print("marker title: \(title): snippet: \(snippet)")
}
}
return true
}
Objective-C
// MARK: GMSMapViewDelegate
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
if (marker.title && marker.snippet) {
NSLog(@"marker with title:%@ snippet: %@", marker.title, marker.snippet)
}
return YES;
}
ควบคุมระดับการมองเห็นเครื่องหมายตามระดับการซูมแผนที่
หากต้องการควบคุมระดับการมองเห็นของ GMSMarker
ให้ใช้โปรโตคอล GMSMapViewDelegate
และเพิ่มเงื่อนไขเพื่อตั้งค่า GMSMarker.map
Swift
// MARK: GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
marker.map = position.zoom >= 14 ? mapView : nil
}
Objective-C
// MARK: GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {
marker.map = position.zoom >= 14 ? mapView : nil;
}
ทำให้เครื่องหมายลากได้
เมื่อเปิดใช้พร็อพเพอร์ตี้ draggable
ผู้ใช้จะลากเครื่องหมายบนแผนที่ได้โดยใช้ท่าทางสัมผัสแบบกดค้าง หากต้องการทำให้เครื่องหมายลากได้ ให้ตั้งค่าพร็อพเพอร์ตี้ GMSMarker.draggable
เป็น true
Swift
marker.draggable = true
Objective-C
marker.draggable = YES;
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eGoogle Maps SDK for iOS allows you to monitor marker events like taps and gestures, displaying information like title and snippet when tapped.\u003c/p\u003e\n"],["\u003cp\u003eYou can enable marker dragging using a long press gesture by setting the \u003ccode\u003eGMSMarker.draggable\u003c/code\u003e property.\u003c/p\u003e\n"],["\u003cp\u003eMarker visibility can be controlled based on the map's zoom level using the \u003ccode\u003eGMSMapViewDelegate\u003c/code\u003e and setting the \u003ccode\u003eGMSMarker.map\u003c/code\u003e property conditionally.\u003c/p\u003e\n"],["\u003cp\u003eTo respond to marker events and access details like title and snippet, implement the \u003ccode\u003eGMSMapViewDelegate\u003c/code\u003e protocol and its corresponding callback methods.\u003c/p\u003e\n"]]],["Markers' events, like taps and gestures, can be monitored by adding `GMSMapViewDelegate`. Tapped markers reveal their title and snippet, set using `GMSMarker.title`. Markers can be made draggable with `GMSMarker.draggable`, allowing movement via long press. You can control marker visibility based on zoom level by setting `GMSMarker.map` within the `GMSMapViewDelegate` callback. Implementing the delegate protocol also allows for handling custom responses to specific marker interactions.\n"],null,["When specific advanced marker properties are set, you can monitor marker events\nsuch as taps and [gestures](/maps/documentation/ios-sdk/controls#map_gestures).\nIf a marker is tapped, one can see additional information such as a marker title\nor snippet. One can also move draggable markers using a long press gesture.\n\n- To track marker events, add the [`GMSMapViewDelegate`](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate) to your `view`.\n- To make a marker draggable, set the [`GMSMarker.draggable`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMarker#draggable) property.\n- To set descriptive text for a marker, use the [`GMSMarker.title`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSOverlay#title) property.\n\nRespond to marker events\n\nYou can respond to [marker events](/maps/documentation/ios-sdk/events) by adding\nthe [`GMSMapViewDelegate`](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate) protocol to your view and\nimplementing the corresponding callback. This example identifies the `title` and\n`snippet` for a selected marker. \n\nSwift \n\n```swift\n// MARK: GMSMapViewDelegate\n\nfunc mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -\u003e Bool {\n if let title = marker.title {\n if let snippet = marker.snippet {\n print(\"marker title: \\(title): snippet: \\(snippet)\")\n }\n }\n return true\n}\n```\n\nObjective-C \n\n```objective-c\n// MARK: GMSMapViewDelegate\n\n- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {\n if (marker.title && marker.snippet) {\n NSLog(@\"marker with title:%@ snippet: %@\", marker.title, marker.snippet)\n }\n return YES;\n}\n```\n\nControl marker visibility by map zoom level\n\nTo control the visibility of [`GMSMarker`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMarker), implement the\n[`GMSMapViewDelegate`](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate) protocol and add a condition to set\n`GMSMarker.map`. \n\nSwift \n\n```swift\n// MARK: GMSMapViewDelegate\n\nfunc mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {\n marker.map = position.zoom \u003e= 14 ? mapView : nil\n}\n```\n\nObjective-C \n\n```objective-c\n// MARK: GMSMapViewDelegate\n\n- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {\n marker.map = position.zoom \u003e= 14 ? mapView : nil;\n}\n```\n\nMake a marker draggable\n\nWhen you enable the `draggable` property users can drag markers on the map with\na long press gesture. To make a marker draggable, set the `GMSMarker.draggable`\nproperty to true. \n\nSwift \n\n```swift\nmarker.draggable = true\n```\n\nObjective-C \n\n```objective-c\nmarker.draggable = YES;\n```"]]