我创建了一个应用程序,它使用 MapKit 在谷歌地图上简单地显示用户的当前位置。
但是,我现在想更进一步,通过允许用户自己在地图上绘制点来为应用程序添加更多功能。
我以某种方式相信使用 CoreLocation 将通过接收和保存用户在地图上选择的位置的坐标来实现这一点。
我这样说对吗?以及我将如何实现这一点的任何想法?链接或教程也会很有帮助,而且任何个人经验/想法都会很棒。
我在这个应用程序之前创建了一个实现 coreLocation 的应用程序,编译/运行完美..只是没有更新用户位置和纬度/经度。该应用程序的代码如下所示:
这仅在 AppDelegate.m 中,它基本上完成了所有工作。
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
@synthesize window;
@synthesize viewController;
@synthesize locationManager;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
self.locationManager = [[CLLocationManager alloc]init];
if ([CLLocationManager locationServicesEnabled]) {
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 100;
[self.locationManager startUpdatingLocation];
}
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
#pragma mark CLLocationManagerDelegate Methods
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
MKCoordinateSpan span;
span.latitudeDelta = 0.2;
span.longitudeDelta = 0.2;
MKCoordinateRegion region;
region.span = span;
region.center = newLocation.coordinate;
[viewController.mapView setRegion:region animated:YES];
viewController.mapView.showsUserLocation = YES;
viewController.latitude.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
viewController.latitude.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
}
@end