尝试在 Mapkit 上显示用户位置,这是有史以来最烦人的事情。有人伸出援手吗?
我正在关注本教程(http ://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/)向应用程序添加mapkit和注释。但是,我在用户位置方面遇到了很大的困难。我是 xcode 新手,所以不太确定下一步该做什么。我尝试过托尼的选择:
step one: add the CoreLocation framework to the project.
Step two: add this function to the iCodeMapViewController.m:
- (void)setCurrentLocation:(CLLocation *)location {
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 0.15f;
region.span.latitudeDelta = 0.15f;
[self.mapView setRegion:region animated:YES];
}
step three: add this code to the ViewForAnnotation Method:
if (annotation != mapView.userLocation) {
//the rest of the ViewForAnnotation code goes here
}else{
CLLocation *location = [[CLLocation alloc]
initWithLatitude:annotation.coordinate.latitude
longitude:annotation.coordinate.longitude];
[self setCurrentLocation:location];
}
但是当我去构建时,它不喜欢它。
我也尝试过这个选项:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
if ([annotation isKindOfClass:MKUserLocation.class]) return nil;
//rest of code
}
蓝点显示,我的自定义注释显示,但当我尝试滚动表格时应用程序崩溃。调试器没有提供任何帮助,但会在此语句处停止。
有人可以帮忙吗?也有代码示例吗?我认为这篇文章的答案可能对许多也在与 Mapkit 作斗争的人有用。
干杯
I'm following this tutorial (http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/) on adding mapkit and annotations to an application. However, i'm seriously struggling with the User Location. I'm new to xcode so not quite sure what to do next. I have tried Tony's option:
step one: add the CoreLocation framework to the project.
Step two: add this function to the iCodeMapViewController.m:
- (void)setCurrentLocation:(CLLocation *)location {
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 0.15f;
region.span.latitudeDelta = 0.15f;
[self.mapView setRegion:region animated:YES];
}
step three: add this code to the ViewForAnnotation Method:
if (annotation != mapView.userLocation) {
//the rest of the ViewForAnnotation code goes here
}else{
CLLocation *location = [[CLLocation alloc]
initWithLatitude:annotation.coordinate.latitude
longitude:annotation.coordinate.longitude];
[self setCurrentLocation:location];
}
But when i go to build, it doesn't like it.
I've also tried this option:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
if ([annotation isKindOfClass:MKUserLocation.class]) return nil;
//rest of code
}
The blue dot shows, my custom annotations show but the app crashes when i try and scroll through the table. The debugger gives no help but does stop on this statement.
Can someone please help? With code examples too? i think the answer to this post might be useful to a number of people also struggling with the mapkit.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有同样的问题,但我设法解决了。
在 cellForRowAtIndexPath 中,我这样做了:
您只需对所有部分重复它即可。
I had the same problem, but I managed to solve it.
In cellForRowAtIndexPath I did this:
You just have to repeat it for all the sections.
听起来您正在尝试将当前位置作为表中的单元格之一...查看您的控制台并在崩溃发生时向我们提供输出。
Sounds like you are trying to include your current location as one of the cells in the table ... look at your console and give us the output when the crash happens.