0
我有一個映射項目,我寫了幾個月後,我用了一個幫助類,它將觸摸參數傳遞給我的主mapview類。使用下面的方法我可以正常轉換CGPoint x和y的信息到一個地理座標:CGPoint到CLLLocationCoordinate2D - convertPoint toCoordinateFromView不工作
- (void)moveDetect:(NSSet *)touches :(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
NSLog(@"X:%f Y:%f", touchPoint.x, touchPoint.y);
CLLocationCoordinate2D touchCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
float lat = touchCoordinate.latitude;
float lng = touchCoordinate.longitude;
NSLog(@"Touch Coordinate: %f %f", lat, lng);}
我最近試圖重用不同項目中的代碼,但轉換不會發生。暫停並逐步進入touchCoordinate變量,最初顯示值(緯度= {CLLocationDegrees} 3.23141e-306和longitude = {CLLocationDegrees} 5.46786e-48),但一旦到達下一行代碼,值都爲0。審查了這兩個項目,但一直無法弄清楚爲什麼一個工程,而另一個不工作。我很欣賞時間,並期待任何可能帶領我走向正確方向的建議。謝謝。
亂搞另外4小時,我終於有一個新的項目開始了,但這次之後,我創造了它僅適用於iPad。測試了代碼並且工作正常,所以顯然項目中的某些內容已損壞。在舊項目中,我刪除了通用項目設置,並將其設置爲僅用於測試iPad,但其行爲完全相同。由於我無法縮小確切的原因,因此我現在不會回答這個問題。 – ninehundredt
作爲一個附註,我還從AppCode創建了原始項目,而不是Xcode,這可能是責任。這個工作項目是在Xcode中創建的,並且像魅力一樣工作。 – ninehundredt