首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MTLocation操作指南

MTLocation操作指南
EN

Stack Overflow用户
提问于 2011-07-10 20:27:56
回答 1查看 640关注 0票数 1

嗨,我刚刚在这里遇到了MTLocation:https://github.com/darkseed/MTLocation

我想在我的应用程序中使用定位我的按钮,该按钮将位于导航栏中,当按下该按钮时,会将地图移动到当前位置。

作者建议使用如下代码:

代码语言:javascript
运行
复制
// Configure Location Manager
[MTLocationManager sharedInstance].locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[MTLocationManager sharedInstance].locationManager.distanceFilter = kCLDistanceFilterNone;
[MTLocationManager sharedInstance].locationManager.headingFilter = 5; // 5 Degrees

// create locate-me item
MTLocateMeBarButtonItem *locateMeItem = [[[MTLocateMeBarButtonItem alloc] initWithLocationStatus:MTLocationStatusIdle] autorelease];
// set delegate that is called when mode of Button changes
locateMeItem.delegate = [MTLocationManager sharedInstance];
// add target-action
[locateMeItem addTarget:self action:@selector(myCustomSelector:) forControlEvents:UIControlEventTouchUpInside];
// disable heading
locateMeItem.headingEnabled = NO;

// create array with ToolbarItems
NSArray *toolbarItems = [NSArray arrayWithObject:locateMeItem];
// set toolbar items
[self.toolbar setItems:toolbarItems animated:NO];

在工具栏中显示locate me按钮很棒,但我们如何才能通过gps显示当前位置?我想我们必须实现myCustomSelector方法,但我不知道如何实现。有什么帮助吗?

EN

回答 1

Stack Overflow用户

发布于 2011-08-18 14:39:54

确保你有

代码语言:javascript
运行
复制
self.mapView.showsUserLocation = YES;

然后实现myCustomSelector:,例如:

代码语言:javascript
运行
复制
- (void) myCustomSelector:(MTLocateMeBarButtonItem*) button {
    [self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate];
}

您需要在不同的按钮模式(无论是MTLocateMeBarButton是空闲的还是其他的)下处理适当的功能,但这应该会给您一个方向。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6641094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档