我現在有一個mapView使用xib文件,當我在mapview中觸摸時,我想要特定區域的經度和緯度,所以有任何乳清或任何示例代碼可以幫助我完成此任務。我怎樣才能獲得任何信息像經緯度,當我在iPhone/iPad上觸摸MKMapView?
1
A
回答
6
對於iOS 3.2或更高版本,使用可能更好更簡單與地圖視圖,而不是嘗試子類化和手動攔截觸摸。
首先,手勢識別添加到地圖視圖:
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(tapGestureHandler:)];
tgr.delegate = self; //also add <UIGestureRecognizerDelegate> to @interface
[mapView addGestureRecognizer:tgr];
[tgr release];
接下來,實施shouldRecognizeSimultaneouslyWithGestureRecognizer
並返回YES
所以你雙擊手勢識別器可以同時工作,作爲地圖的(否則輕叩引腳贏得」噸得到由地圖自動處理):
最後,實現手勢處理機:
- (void)tapGestureHandler:(UITapGestureRecognizer *)tgr
{
CGPoint touchPoint = [tgr locationInView:mapView];
CLLocationCoordinate2D touchMapCoordinate
= [mapView convertPoint:touchPoint toCoordinateFromView:mapView];
NSLog(@"tapGestureHandler: touchMapCoordinate = %f,%f",
touchMapCoordinate.latitude, touchMapCoordinate.longitude);
}
1
它是一種棘手的事情要做。
首先,你需要繼承的MKMapView
在
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
方法,你可以找到觸摸的位置,然後用這個方法
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view
你可以找到lat和長..
0
在斯威夫特3:
func tapGestureHandler(_sender: UITapGestureRecognizer) {
let touchPoint = _sender.location(in: mapView)
let touchMapCoordinate = mapView.convert(touchPoint, toCoordinateFrom:mapView)
print("latitude: \(touchMapCoordinate.latitude), longitude: \(touchMapCoordinate,longitude)")
}
相關問題
- 1. 我怎樣才能在twitter上獲得過去的信息?
- 2. 我怎樣才能獲得的緯度和經度從JSON谷歌地圖
- 3. 我怎樣才能獲得緯度和經度值從UDP數據包的C#
- 4. iOS - 我怎樣才能返回經度和緯度?
- 5. 我怎樣才能獲得更多的信息在Facebook登錄
- 6. Bing地圖。我怎樣才能得到緯度和經度的地址?
- 7. 我怎樣才能獲得actionName在ActionFilter
- 8. Android ImageView:我怎樣才能獲得當前的旋轉角度?
- 9. 我怎樣才能得到
- 10. 我怎樣才能得到
- 11. 我怎樣才能得到多個成像視圖與觸摸移動標籤?
- 12. 我怎樣才能獲得JSON值
- 13. 我怎樣才能獲得R中
- 14. 我怎樣才能獲得訪問Android
- 15. 我怎樣才能獲得價值? Odoo
- 16. 我怎樣才能獲得文本QTableWidgetItem
- 17. 我怎樣才能獲得列表框
- 18. 我怎樣才能獲得的java.awt.geom
- 19. 我怎樣才能獲得值「111」
- 20. 如果通過本機觸摸關閉鍵盤,我怎樣才能獲得iPhoneKeyboard.done?
- 21. 我們如何才能在PhoneGap中獲得準確的緯度,經度?
- 22. 我怎樣才能找到當前經度和使用HTML5
- 23. 我怎樣才能確保沒有任何獲得autoreleased?
- 24. 我怎樣才能得到一個例外字典信息?
- 25. 我怎樣才能讓我的android應用正確顯示在觸摸板上?
- 26. 角谷歌地圖使用控制器我怎樣才能得到(經度和緯度)當前地圖的中心獲取地圖的經緯度中心
- 27. 我怎樣才能得到當前位置經緯度值在PHP中使用android
- 28. 谷歌地圖API - 我怎樣才能獲得特定國家的緯度和經度
- 29. 我怎樣才能在鉻上的div上獲得keydown事件?
- 30. 經/緯度信息
感謝很多人它的工作不錯.... –