0

我在一个简单的 iPhone 应用程序中使用 MapView 和 CoreLocation ... CoreLocation 正确显示了我的纬度和经度:

[Session started at 2012-07-08 20:11:35 +0200.]
2012-07-08 20:11:37.082 WhereAmI[5095:207] <+52.37609766, +4.92279518> +/- 70.00m (speed    0.00 mps / course -1.00) @ 7/8/12 8:11:33 PM Central European Summer Time
2012-07-08 20:11:38.605 WhereAmI[5095:207] <+52.37609766, +4.92279518> +/- 70.00m (speed 0.00 mps / course -1.00) @ 7/8/12 8:11:38 PM Central European Summer Time

但是,当我运行时:

[mapView setShowsUserLocation:YES];

突出显示的位置是加利福尼亚的 AppleHQ,而不是阿姆斯特丹 <+52.37609766, +4.92279518>?

从控制台日志记录中,我确实发现了这个“用户位置视图不可见”错误:

2012-07-08 20:11:46.600 WhereAmI[5095:207] User location view is NOT visible but should be. Showing....

我确实对此进行了搜索,并被建议运行:

mapView.userLocationVisible;

这执行正常,但没有区别?

4

2 回答 2

1

确保在您的 Xcode 中您没有使用模拟位置。单击调试栏中的箭头按钮(如下所示)并选择“不模拟位置”。在所附图片上,您想要的按钮在右侧。

编辑:此答案仅适用于 Xcode 4 及更高版本。Xcode 3 中没有位置模拟功能。

你想要的按钮在这张图片的右边

于 2012-07-08T20:27:14.857 回答
0

Running mapView.userLocationVisible but itself will do nothing. It gives you a value and you need to do something with it.

If the blue pin is showing up in California (the only place it will appear when using the simulator on older XCodes) and you're reading lat/longs in Amsterdam, then you'll need to show us how you are getting those lat/longs because iOS can't think it is in two places at once, you must have set one of them manually.

When it comes to setting the map view to look at your location, I would have advised UserTrackingMode, but if you're on XCode 3.x you're probably not on the latest iOS so try

- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated

or any of the related functions under the "Manipulating the visible portion of the map" section from the class reference
http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html

于 2012-07-09T20:42:13.217 回答