嗨,我刚刚在这里遇到了MTLocation:https://github.com/darkseed/MTLocation。
我想在我的应用程序中使用定位我的按钮,该按钮将位于导航栏中,当按下该按钮时,会将地图移动到当前位置。
作者建议使用如下代码:
// 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方法,但我不知道如何实现。有什么帮助吗?
发布于 2011-08-18 14:39:54
确保你有
self.mapView.showsUserLocation = YES;
然后实现myCustomSelector:,例如:
- (void) myCustomSelector:(MTLocateMeBarButtonItem*) button {
[self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate];
}
您需要在不同的按钮模式(无论是MTLocateMeBarButton是空闲的还是其他的)下处理适当的功能,但这应该会给您一个方向。
https://stackoverflow.com/questions/6641094
复制相似问题